Jump to content

nl2br doesnt work


supanoob

Recommended Posts

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);

 

Link to comment
https://forums.phpfreaks.com/topic/210889-nl2br-doesnt-work/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/210889-nl2br-doesnt-work/#findComment-1100040
Share on other sites

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?

Link to comment
https://forums.phpfreaks.com/topic/210889-nl2br-doesnt-work/#findComment-1100199
Share on other sites

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?

 

Link to comment
https://forums.phpfreaks.com/topic/210889-nl2br-doesnt-work/#findComment-1100240
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.