supanoob Posted August 16, 2010 Share Posted August 16, 2010 I have the following code, and for some reason the nl2br() function doesnt work anymore it did until i added the pred_replace part: $topic = $_POST['topic']; $message = $_POST['message']; $board = $_POST['board']; $topic = stripslashes($topic); $message = stripslashes($message); $board = stripslashes($board); $topic = mysql_real_escape_string($topic); $message = mysql_real_escape_string($message); $board = mysql_real_escape_string($board); $message = nl2br($message); $message = preg_replace("/\[b\](.*)\[\/b\]/Usi", "<b>\\1</b>", $message); $message = preg_replace("/\[u\](.*)\[\/u\]/Usi", "<u>\\1</u>", $message); $message = preg_replace("/\[i\](.*)\[\/i\]/Usi", "<i>\\1</i>", $message); $message = preg_replace("/\[center\](.*)\[\/center\]/Usi", "<center>\\1</center>", $message); $message = preg_replace("/\[right\](.*)\[\/right\]/Usi", "<p align=right>\\1</p>", $message); $message = preg_replace("/\[url=http://(.*)\](.*)\[\/url\]/Usi", "<a href=\"\\1\">\\2</a>", $message); $message = preg_replace("/\[img=(.*)\]/Usi", "<img src=\"\\1\">", $message); $message = preg_replace("/\[profile=(.*)\](.*)\[\/profile\]/Usi", "<a href=\"index.php?step=profile&profile=\\1\">\\2</a>", $message); $message = preg_replace("/\[quote](.*)\[\/quote\]/Uis", "<div>Quote:</div><div style=\"border:solid 1px;\">\\1</div>", $message); Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted August 17, 2010 Share Posted August 17, 2010 Are you parsing this then entering it into a database? Or is this being parsed to display on the page? It looks like you're getting ready to enter it into a database, in which case you shouldn't bother about converting everything to html markup. Do that when you retrieve the data from the database. I generally do nl2br as the last thing as well, so try shifting it to the bottom. Quote Link to comment Share on other sites More sharing options...
supanoob Posted August 17, 2010 Author Share Posted August 17, 2010 Are you parsing this then entering it into a database? Or is this being parsed to display on the page? It looks like you're getting ready to enter it into a database, in which case you shouldn't bother about converting everything to html markup. Do that when you retrieve the data from the database. I generally do nl2br as the last thing as well, so try shifting it to the bottom. Yeah im putting it into a database, but if i get rid of the nl2br it doesnt work either, nor does putting it below everything else :S someone mention it could be to do with Usi flags? Quote Link to comment Share on other sites More sharing options...
supanoob Posted August 17, 2010 Author Share Posted August 17, 2010 Are you parsing this then entering it into a database? Or is this being parsed to display on the page? It looks like you're getting ready to enter it into a database, in which case you shouldn't bother about converting everything to html markup. Do that when you retrieve the data from the database. I generally do nl2br as the last thing as well, so try shifting it to the bottom. Just an update i have also tried using preg_replace for the \r\n etc aswell as str_replace for the same thing, nothing seems to be working , i put for example i put: This is A Test Thats exactly how it would get inserted into my database, Just without any <br />'s. The field it is going into is formatted as "longtext" not sure if that makes a difference or not? Quote Link to comment 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.