Forum Moderators: coopster
Is there any reason that nl2br would not replace newlines with <br>?
I'm using this in an SQL statement to insert a block of text into my MySQL database. Every time I try this the <br>'s are never there and the line breaks are.
I even used this function from another thread in this forum and it doesn't work:
$content = explode("\n",$message);
foreach($content as $key => $line) {
$lines[$key] = $line;
}
$content = implode("<br>",$lines);
Even if I try to replace \r or the combination of \r\n it still doesn't work.
I need some guidance...
Let me add a little more to this...
I'm collecting the text in a <textarea> of a form, then getting the data using:
if(get_magic_quotes_gpc()) {
$message = mysql_real_escape_string(stripslashes($_POST["message"]));
} else {
$message = mysql_real_escape_string($_POST["message"]);
};
Then adding:
$message = nl2br($message);
and my SQL statement:
"insert into table (Message) values ('".$message."')"
but the text appears in the database just as I typed it, no newlines replaced.