How do you keep your X/HTML tidy with PHP?

Evan W

New member
When ever I use the echo function and make html and such, I view the page source and its all squished together (its valid but unreadable). What can I do in PHP to make this cleaner?
<p>Blahblah</p><p>BlahblahBlahblahBlahblah</p><p>
Blahblah<br />Blahblah<br />Blahblah</p>

Yeah, Its all one big line. I want it to be properly formated.
 
I used to have the same problem. There's this lovely thing called a line break. Lol

It is

\n

You use it in the print function.
Ex:
Instead of
echo "<div><p>Text Text</p></div>";
echo "<a href=\"asdf.org\">ASDF</a>";

Which will output
<div><p>Text Text</p></div><a href=\"asdf.org\">ASDF</a>

Type

echo "<div><p>Text Text</p></div>\n";
echo "<a href=\"asdf.org\">ASDF</a>";

Note the \n at the end of the first echo.

It will print as

<div><p>Text Text</p></div>
<a href=\"asdf.org\">ASDF</a>

You can put the \n wherever you want in a print or echo function and it will create a line break in the X/HTML document source.

=]
 
I used to have the same problem. There's this lovely thing called a line break. Lol

It is

\n

You use it in the print function.
Ex:
Instead of
echo "<div><p>Text Text</p></div>";
echo "<a href=\"asdf.org\">ASDF</a>";

Which will output
<div><p>Text Text</p></div><a href=\"asdf.org\">ASDF</a>

Type

echo "<div><p>Text Text</p></div>\n";
echo "<a href=\"asdf.org\">ASDF</a>";

Note the \n at the end of the first echo.

It will print as

<div><p>Text Text</p></div>
<a href=\"asdf.org\">ASDF</a>

You can put the \n wherever you want in a print or echo function and it will create a line break in the X/HTML document source.

=]
 
Back
Top