2014-07-02 55 views
0

我想知道PHP如何對待白色空間。減少我的php編碼中的空格PHP如何對待白色空間

  • 會減少頁面加載時間嗎?
  • 將減少我的視圖源中的空白空間嗎?
  • 會減少我的程序編譯時間嗎?我的代碼

<?php 
include('head.php'); 
-- Here is white space -- 
include('body.php'); 
-- Here is white space -- 
include('footer.php'); 
?> 

內body.php

<?php 

echo $lhs = '<div class="lhs">my content</div>'; 



    white 

    spaces.. 


echo $main = '<div class="main">my content</div>'; 

    white 

    spaces.. 


echo $footer ='<div class="footer">my content </div>'; 

?> 

我的生活符號化部

<?php include('config.php'); ?> 
<!DOCTYPE HTML> 
<html> 
<?php include(ROOT.'head.php'); ?> 
<body> 
<div id="container">   
    <?php 
    // header items => logo , searchbar , compare , myaccount/login 
    include(ROOT.'headeritems.php'); 
    //WEBSITE MENUS 
    include(ROOT.'sitemenus.php');  
    if ($page!="index"){ include(ROOT.'otherpagenotification.php'); } 
    ?>   
     <div id="breadO" <?php echo ($page!="index")? 'class="bannerShd2"' :''; ?> > 
     <div id="bread"> 
      <?php include(BREADCRUMBS); ?> 
     </div> 
     </div> 
</div> 

HTML查看源

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" /> 

行號1至4是空白像這樣的很多都是在我看來源

+5

從PHP源中刪除空格除了可能的代碼可讀性之外,不會對任何事物產生明顯的影響。 –

+0

我不認爲空白對性能有很大的作用..但是它們可以增加可讀性和文件大小。 –

+0

瞭解PHP腳本的內容不會被客戶端下載 - 只是輸出。 – Marty

回答

1

其實PHP腳本白色是沒有問題的,如果你用白內php腳本之前和之後的空間意味着

-------Space----- 
<?php 

?> 

-----Space --- 

會產生一個稱爲Header Problems的錯誤。你會得到一個錯誤,如follwing

Warning: Cannot modify header information - headers already sent by (output 
started at /some/file.php:12) in /some/file.php on line 23 

儘量避免像

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" /> 

欲瞭解更多詳情,請查看以下鏈接空白: How to fix "Headers already sent" error in PHP

0

問:會降低頁面加載時間? 答:沒有

問:在我的視圖源中是否會減少空白空間? 答:沒有

問:會減少我的程序編譯時間嗎? 答:沒有

0

PHP 忽略白色空格。在網頁源代碼中的白色空間是不是從你的php file.You錯過了一些東西

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> 
0
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