Page 1 of 1
[SOLVED] nl2br
Posted: Sun Mar 14, 2004 11:01 am
by Rahil
How can I un-nl2br something? Like, for a news script, when I'm adding news in a textarea, I want it to nl2br then put it in the database. Then on my news page, I want it to echo what ever is in the database. Now, if I want to edit the news post, I go back to the textarea, but I don't want to see the <br /> and other HTML. How could i un-nl2br it? Thanks.
Posted: Sun Mar 14, 2004 11:03 am
by markl999
Just don't nl2br() it before putting it in the database. Only nl2br() on the news page before echoing it out, the textarea on the edit page will then still show the original newlines (that are in the db).
Posted: Sun Mar 14, 2004 11:09 am
by Ixplodestuff8
Mark's idea is best, but incase it's too late and your news is already with the br's try this:
str_replace ( '<br />', '', $the_thingy );
it will get rid of all <br />'s, the only downside is that if a <br /> was entered manually and not by nl2br it'll get cut off aswell
Posted: Sun Mar 14, 2004 11:24 am
by Rahil
Thanks guys. Problem solved

Posted: Sun Mar 14, 2004 1:25 pm
by m3mn0n
Ixplodestuff8 wrote:Mark's idea is best, but incase it's too late and your news is already with the br's try this:
str_replace ( '<br />', '', $the_thingy );
it will get rid of all <br />'s, the only downside is that if a <br /> was entered manually and not by nl2br it'll get cut off aswell
To take that a step further:
Code: Select all
<?php
function un_nl2br ($string)
{
$string = str_replace ("<br />", "\n", $string);
return $string;
}
?>