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.

Link to comment
Share on other sites

<?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>";

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.