How PHP treats White Spaces

前端 未结 4 1292
臣服心动
臣服心动 2021-01-28 04:07

I would like to know how php treats white spaces. Reducing a white spaces in my php coding

  • will reduce the page loading time ?
  • Will reduce empty spaces
相关标签:
4条回答
  • 2021-01-28 04:31

    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

    0 讨论(0)
  • 2021-01-28 04:31
    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
    
    0 讨论(0)
  • 2021-01-28 04:44

    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>
    
    0 讨论(0)
  • 2021-01-28 04:55

    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

    0 讨论(0)
提交回复
热议问题