Recently I was printing out some HTML source for a project I’ve been working on. I like to keep my markup tidy and readable. I noticed that in some places there are no line breaks on the outputted html and in some places there is excess indentation. For example take the following code, where I have preserved the indentation from the source file:
<div id="sections">
<ul>
<?php if(!empty($details)) { ?>
<li><a href="#details"><span>Details</span></a></li>
<?php } if(!empty($address) { ?>
<li><a href="#viewmap"><span>Location Map</span></a></li>
<?php } if(!empty($reviews) { ?>
<li><a href="#reviews"><span>Reviews (<?php echo $numrows; ?>)</span></a></li>
<?php } if($email != null) { ?>
<li><a href="#sendemail"><span>Send an Email</span></a></li>
<?php } ?>
</ul>
The generated HTML output is as follows:
<div id="sections">
<ul>
<li><a href="#details"><span>Details</span></a></li>
<li><a href="#viewmap"><span>Location Map</span></a></li>
<li><a href="#sendemail"><span>Send an Email</span></a></li>
</ul>
</div>
Here we can see the DIV and UL tags have two tab indents from the left – this is fine. However the LI tags have 5 indents from the left – it should only be 3 if it goes according to my code. The end UL tag also has two extra indents.
Is this just the expected behaviour or can this be rectified somehow?
So? The output is matching your code perfectly. I don’t get, why there would be a problem?
Delete the php code and you see that the numbers of tabs and newlines match.
Oh and btw: The first ul should have a tab more, because it’s inside the div.