Click to See Complete Forum and Search --> : htmlspecialchars display problem


bugman
09-24-2006, 11:03 AM
Okay, am I the only one having a problem with this? I have the following code:


$testHTML=<<<END
<html>
<head>
</head>
<body>
hi
</body>
</html>
END;
echo htmlspecialchars($testHTML);


Everything works except.... The HTML tags are all displayed in one line, not one line per tag as shown above. That could get pretty confusing with a large page. What am I doing wrong? Thanks.

ronverdonk
09-24-2006, 11:10 AM
Nothing really wrong. You just have to convert the newline chars (\n) in the <<<END .... END; string to html breaks. As in
echo nl2br(htmlspecialchars($testHTML));
Ronald :cool:

bugman
09-24-2006, 11:29 AM
Thanks. Now on to the coding!

NogDog
09-24-2006, 12:01 PM
Or:

echo "<pre>".htmlspecialchars($testHTML)."</pre>\n";