stripping html tags

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
chaza
Forum Newbie
Posts: 10
Joined: Fri Oct 10, 2003 11:28 am

stripping html tags

Post by chaza »

I am trying to edit a txt file that I have written previously.
the writing script uses the nl2br() function to add a <br />
When I read the file into a textarea to edit it, it displays all the <br /> tags.
How can I get rid of the line break tags when it displays for editing?
I have played around with strip_tags() with no success.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

You shouldn't use nl2br() before writing the text to file - only when you're formatting the text for display (other than editing).

To remove those <br />'s use [php_man]str_replace[/php_man]():

Code: Select all

$text = str_replace('<br />', '', $text);
but change your script so in the future you don't use nl2br() in the writing script only in the final display script.

Mac
Post Reply