panthro panthro - 2 months ago 7
PHP Question

Outputting a string of HTML

I'm adding my HTML to a var:

$html = '';
$html .= '<li>';
$html .= '<p>hello</p>';
$html .= '</li>';
....
echo $html


When I view the page's source the above is all output on one line. How can I fix it so that we see the layout as you would if it was written:

<ul>
<li>
<p>hello</p>
</li>
...

Answer

Add newlines with \n and tabs with \t:

$html = '';
$html .= "<li>\n";
$html .= "\t<p>hello</p>\n";
$html .= "</li>\n";
Comments