nl2br not working [Solution]

If you use nl2br and its not working, check to see if you are using mysql_real_escape_string before it. nl2br may not work when trying to convert carriage returns - newlines (rn) if mysql_real_escape_string is called before nl2br.

That said, if you want to use them together, either call nl2br before mysql_real_escape_string or use something like the following:

$stringOut = str_replace("\\r\\n", "< br />", $stringIn);

For my situation, I run all my POST vars through mysql_escape_string in a Foreach loop at the beginning of the script; so I used the code above after mysql_real_escape_string was called and it worked.

I hope this helps.

Keywords: nl2br not working with \\r\\n


Submit a Comment