Page 1 of 1

Indent PHP Echoes With HTML

Posted: Mon Jul 28, 2008 10:19 am
by Thomas-T
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

Posted: Mon Jul 28, 2008 10:35 am
by mabwi
You can do this:

Code: Select all

 
  print "\n\t";
 
That will print a new line and then a tab.

Re: Indent PHP Echoes With HTML

Posted: Mon Jul 28, 2008 6:14 pm
by manixrock
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:

Code: Select all

<div>
<? if($someUglyVariable) { ?>
    <b>I HAVE A TABS BEFORE ME!!</b>
<? } ?>
</div>
Except small php insertion codes, or ugly but practical cases where you need the html on one line:

Code: Select all

And then he <? if($quote) { ?>said "<?=htmlspecialchars($quote)?>"<? } else { ?>said.. nothing.<? } ?>