Replacing <br> with new lines problem

I am trying to convert text with <br> or <BR> etc into new line characters.

I was using this code:


$text = preg_replace( '<br>', "\
", $text);
$text = preg_replace( '<BR>', "\
", $text);

$text = str_replace( "<", "", $text);
$text = str_replace( ">", "", $text);

However it doesnt work. preg_replace( ‘<br>’, "
", $text); replaces <br> with </n> (which is why I then need to do str_replace( “<”, “”, $text); )

And str_replace( ‘<br>’, "
", $text); replaces <br> with br…

Try this.

AFAK \ has a special meaning so you have to escape with /


$text = preg_replace( '/<br>/', "\
", $text);
$text = preg_replace( '/<BR>/', "\
", $text);

thanks, but that doesnt seem to help. Just leaves a load of / characters in the document

sorry, my mistake, I’ve changed my last post, hope this one is good

/ starting and ending delimiters

i means case insensitive


$text = preg_replace( '/<br>/i', "\
", $text);

function br2nl($str) {
$str = preg_replace(“/(\r
|
|\r)/”, “”, $str);
return preg_replace(“=<br */?>=i”, "
", $str);
}

Hello my firend

http://www.php.net/manual/en/function.nl2br.php

Look at User Contributed Notes,You can find good points.

GOOD LUCK!