I would like to know how php treats white spaces. Reducing a white spaces in my php coding
Actually inside the PHP script white there is no problem, in case if you use white space before and after php script which means
-------Space-----
<?php
?>
-----Space ---
will make an error called Header Problems. You will get an error like follwing
Warning: Cannot modify header information - headers already sent by (output
started at /some/file.php:12) in /some/file.php on line 23
Try to avoid white space like
1.
2.
3.
4.
5. <!DOCTYPE HTML>
6. <html>
7. <head>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Samsung Galaxy Note 3</title>
<link rel="shortcut icon" href="favicon.ico" />
<meta name="description" content="" />
<meta name="author" content="name" />
<meta name="rating" content="General" />
For more details please check the following link: How to fix "Headers already sent" error in PHP
This Is Space After Calling Html Code File.
Like Inside Function.php Or Our Custome Function File Included(widget File, Meta Box File.etc BackEnd File) Space.
Please Remove Between Two Function Space Like As
WRONG :
<?php
function 1....
?>
[consider As A HTML Space]---------Remove This Part
<?php
function 2....
?>
Right :
<?php
function 1....
function 2....
?> No Break Between Two Function
<?php
Code ....
?>
End Check Last Of File Remove Extra Spaces
PHP ignores white spaces. The White spaces in your page source is not from your php
file.You are missing out of some thing
FYI
<html>
<?php
echo 1;
/*
These white space will be ignored by php , It won't affect your HTML code
*/
echo 2;
?>
<!-- But this white spaces above or below PHP tag will be reflected in HTML source code -->
</html>
Q: Will reduce the page loading time ? A: No
Q: Will reduce empty spaces in my view source ? A: No
Q: Will reduce my program compiling time ? A: No