On my website, users have the ability to post comments. Comments get inserted into my mysql database as plain text. When displaying the comments back, I am trying to use the php nl2br() function to allow it to display line breaks as <br /> tags, but it doesn't work. I've noticed when the text gets posted to the database it does not capture the '\n'. Should it? I'd really appreciate if anyone could help with why carriage returns are not being captured / displayed right.
The following code gets the comment and formats it safe before inserting to the database.
$comment = $_GET["comment"];
if(get_magic_quotes_gpc())
{
$comment = stripslashes($_GET["comment"]);
}
else
{
$comment = $_GET["comment"];
}
$comment = trim($comment);
$comment = preg_replace('/\s+/', ' ', $comment);
$comment = mysql_real_escape_string($comment);
$comment = ereg_replace("<[^>]*>","",$comment);
I am then trying to display it as:
echo nl2br(htmlentities($row["comment"]));
**Note: I've tried commenting out everything but the "$comment = $_GET["comment"];" line before inserting to database, but still no luck. I've also tried removing the htmlentities before displaying, but no luck.
Thanks!!