Page 1 of 1

nl2br not working

Posted: Tue Apr 22, 2008 1:17 pm
by psychotomus

Code: Select all

            $user = mysql_real_escape_string($_POST['textUser']);
            $arti = nl2br(strip_tags(mysql_real_escape_string($_POST['textArticle'])));
            $title = strip_tags(mysql_real_escape_string($_POST['textTitle']));
            $cat = mysql_real_escape_string($_POST['select']);
            $time = time();
            
            mysql_query("INSERT INTO sim_articles (title, content, cat, added) VALUES ('$title','$arti','$cat','$time')") or die(mysql_error());
            $msg = "Article Successfully submitted";

when i display the article from sim_articles $content. it displays everything on one line. any ideas why?

Re: nl2br not working

Posted: Tue Apr 22, 2008 2:51 pm
by markusn00b
Try reordering your functions on the POSTed string, so that nl2br() is parsed before mysql_real_escape_string():

Code: Select all

 
# connect mysql for tests sake
 
echo nl2br("new\nline"); # works fine
/*
| prints
| new<br />line
*/
echo nl2br(mysql_real_escape_string("new\nline"); # doesn't work
/*
| prints
| new\nline
*/
echo mysql_real_escape_string(nl2br("new\nline"); # works also, to a degree.
/*
| prints
| new
| \nline
*/