Indent PHP Echoes With HTML
Moderator: General Moderators
Indent PHP Echoes With HTML
When I view the source code for my PHP, I've noticed that the PHP doesn't indent in the same way as my HTML. What I mean by that is I always indent my HTML with a tab, so that it's easier to see where everything is, and it just looks a lot neater. However, if I use PHP code in the middle of my HTML, the PHP code is not in-line with my HTML. In other words, the HTML generated by the PHP (as PHP isn't displayed in the source code) is always aligned left, and it looks very messy. I've discovered how to use line breaks in the PHP code, so that I don't have to scroll right to view all the code, but now I'm having a bit of trouble getting the PHP to indent with my HTML, so that everything looks nice and tidy. Does anyone have any suggestions? Would it be easier to not bother indenting the HTML, so that everything is aligned to the left?
Re: Indent PHP Echoes With HTML
You can do this:
That will print a new line and then a tab.
Code: Select all
print "\n\t";
Re: Indent PHP Echoes With HTML
PHP only lines are not outputted at all.
You should always keep your html and php on different lines, so that the html lines contain their own tabs:
Except small php insertion codes, or ugly but practical cases where you need the html on one line:
You should always keep your html and php on different lines, so that the html lines contain their own tabs:
Code: Select all
<div>
<? if($someUglyVariable) { ?>
<b>I HAVE A TABS BEFORE ME!!</b>
<? } ?>
</div>Code: Select all
And then he <? if($quote) { ?>said "<?=htmlspecialchars($quote)?>"<? } else { ?>said.. nothing.<? } ?>