The Codesee The Codesee - 5 months ago 27
PHP Question

Unexpected Whitespace in Source Code Viewer

Using if and echo statements in the code below is causing a blank whitespace to appear (on line 4 in this instance) when viewing my website's source using Google Chrome:

enter image description here

<ul>
<li>Hi</li>
<li>Hello</li>
<?php
if($something) {
echo'
<li>1</li>
<li>2</li>
';
}else{
echo'
<li>2</li>
<li>1</li>
';
}
?>
</ul>

Answer

The very first character after the ' is a new line.

echo'
   <li>1</li>
   <li>2</li>
   ';

This should get rid of it:

echo'<li>1</li>
   <li>2</li>
   ';