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
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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.