Hi

Ive been using the nl2br function on text that users input... which has been great, but if they want to edit that text later, its riddled with <br />'s etc... is there a way of stripping these html tags out of the code before its displayed in the 'edit' textarea?

Thanks
lworks

While fetching, use str_replace to replace "<br />" with "".
ie.,

str_replace("<br />", "", $data);

Nav33n's proposal will return a string with no spaces, instead with new lines where the breaks are.
In order to return a string with line breaks, you should replace <br /> with \n , store it in a variable and then return the variable value as evaluated string.

Doing it like this:

$mytext = str_replace("<br />", "\n", $formatted_text);
echo "$mytext";

The above should validate the variable content whether it contains php code and execute it. So, the \n will actually cause the string to be returned with new lines in it.

@Rhyan, \n will return extra line breaks. For example, If the actual string is

ab
bc

\n will return

ab 

bc
Comments
sounds right to me :)

Hm,
Appears you are right.
It really does not replace new line indicator by html equivalent <br /> it only inserts it before the new line indicator. Odd....
So instead using nl2br, you can use str_replace ("\n", '<br />', $string) to get the new lines correctly substituted....
Obviously the decision how would you do it depends on which one is faster.
So, I suppose nl2br should be faster when reverting to plain text...

This question has already been answered. Start a new discussion instead.