nl2br not working

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
psychotomus
Forum Contributor
Posts: 487
Joined: Fri Jul 11, 2003 1:59 am

nl2br not working

Post 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?
User avatar
markusn00b
Forum Contributor
Posts: 298
Joined: Sat Oct 20, 2007 2:16 pm
Location: York, England

Re: nl2br not working

Post 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
*/
 
Post Reply