shamuraq Posted January 15, 2012 Share Posted January 15, 2012 Hi... I read on php.net manual that its better to use str_replace than preg_replace. I used $summary = clean($_POST['summary']); $summary = nl2br($summary); to convert the carriage return(is that the correct term?) to insert them into mysql. So naturally, i want them converted into <br> when i pull them from mysql. I used this: $num_rows=mysql_num_rows($result); if($num_rows == 0){ } else{ for($x = 0; $x < $num_rows; $x++){ $row = mysql_fetch_assoc($result); $id = $row['id']; $position = $row['position']; $summary = $row['summary']; $order = array("\r\n", "\n", "\r"); $replace = '<br />'; $newstr = str_replace($order, $replace, $summary); But i got this error: Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in /home/...php on line 310 Is it a syntax error? Thanx in advance... Quote Link to comment https://forums.phpfreaks.com/topic/255039-help-on-str_replace/ Share on other sites More sharing options...
trq Posted January 15, 2012 Share Posted January 15, 2012 nl2br already coverts newlines to <br /> tags. You shouldn't do this on the way into the database however, only on the way out. Quote Link to comment https://forums.phpfreaks.com/topic/255039-help-on-str_replace/#findComment-1307731 Share on other sites More sharing options...
shamuraq Posted January 15, 2012 Author Share Posted January 15, 2012 nl2br already coverts newlines to <br /> tags. You shouldn't do this on the way into the database however, only on the way out. Followed ur advice and removed the nl2br from the insert into sql file. But am still getting the same error. Quote Link to comment https://forums.phpfreaks.com/topic/255039-help-on-str_replace/#findComment-1307736 Share on other sites More sharing options...
shamuraq Posted January 15, 2012 Author Share Posted January 15, 2012 Solved it... I guess the problem is because am trying to store it in a variable... But i changed to to echo nl2br("$summary"); But am curious tho... Is there anyway to store it in a variable without causing those errors? Quote Link to comment https://forums.phpfreaks.com/topic/255039-help-on-str_replace/#findComment-1307738 Share on other sites More sharing options...
Pikachu2000 Posted January 15, 2012 Share Posted January 15, 2012 There shouldn't be any reason it won't work. $newvar = nl2br( $oldvar ); Quote Link to comment https://forums.phpfreaks.com/topic/255039-help-on-str_replace/#findComment-1307740 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.