I am literally about to start tearing my hair out...
I'm building a site that allows users to post ads. These ads will be stored in a MySQL database so obviously I'm passing the values through mysql_real_escape_string before storing them BUT, of course, the main description may have line breaks in it that I want to preserve so when displaying
the ad, I use nl2br. Sounds simple, right? Except it's not working, it's as thought nl2br is just ignoring the \r etc.
At the moment I'm working on the ad preview so my description is coming into the preview page via a session variable $_SESSION['m_desc'] and all I'm putting is
echo nl2br($_SESSION['m_desc']);
(inside php tags, of course). But the string just comes out with the \r\n s still in there.
I've shown the $_SESSION variables using print_r and m_desc looks like this:
Array
(
[m_desc] => Line One\r\nLine Two\r\nLine Three
)
and that's exactly how it's shown on screen AFTER nl2br. To really make me scream, if I replace the session variable with a test one, e.g.
$teststr="Line One\r\nLine Two\r\nLine Three";
echo nl2br($teststr);
it works perfectly! It's as though the session variable isn't really a string but I'm completely stumped.
Any help greatly appreciated!
Jon