panthro panthro - 1 year ago 109
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:


Answer Source

Add newlines with \n and tabs with \t:

$html = '';
$html .= "<li>\n";
$html .= "\t<p>hello</p>\n";
$html .= "</li>\n";
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download