Jump to content

php indent or tab character (kinda of like \n only indents)


s0c0

Recommended Posts

Does this exist?  I have a class that outputs lots of HTML and I would like to make it pretty under the hood by properly indenting my HTML.  Why you ask?  Because I am seriously that anal.  Is there something easy that will do this for me?  I was thinking there would be something like \n or \r except like \t or \i that does a tab/indent.  Seriously nothing pisses me off more than when a developer outputs an assload of HTML via PHP you view source and its one long unreadable line.

 

Thanks.

<?php
echo "<table border='1'>\n";
echo "\t<tr>\n";
echo "\t\t<td>Hello World</td>\n";
echo "\t</tr>\n";
echo "</table>\n";

?>

 

Gives -->

<table border='1'>
<tr>
	<td>Hello World</td>
</tr>
</table>

 

But so would this, and it's more readable

<?php
echo "<table border='1'>
    <tr>
        <td>Hello World</td>
    </tr>
</table>";

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.