strip_tags and nl2br
| From: | James Colannino | Date: | Wed, 21 May 2008 05:58:07 +0000 |
| Subject: | strip_tags and nl2br | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-274588@lists.php.net to get a copy of this message | ||
Hey everyone,
I have a little bit of a quandry. I need to strip HTML tags from user input, but I also need to convert \n's from the textarea elements to <br> tags so it will display properly in a browser.
nl2br() works just fine, but if I use strip_tags first, then run nl2br, nl2br won't work as expected. Instead, everything shows up on a single line.
I understand why it won't work if I place a call to nl2br inside a call to strip_tags, but strip_tags doesn't get rid of \n's, right?
I'm making my calls like this:
$string = strip_tags($_SESSION['variable']);
$string = nl2br($string);
I would expect that to work, but it doesn't :( Am I missing something? I originally placed the call to strip_tags inside the call to nl2br, but when that didn't work, I tried doing these calls separately.
Thanks!
James
--
My blog: http://www.crazydrclaw.com/
My homepage: http://james.colannino.org/
"When you do the common things in life in an uncommon way, you will
command the attention of the world." --George Washington Carver