Discussion:
strip_tags
Tedd Sperling
2013-07-20 16:25:14 UTC
Permalink
Hi gang:

I've been using

$str = strip_tags($str, $allowable)

as it is described via the manuals:

http://php.net/manual/en/function.strip-tags.php

The problem I've found is the tags "<br>" and "<br />" are not stripped.

How do you strip all tags, but leave some tags (such as <b>, <i>, and <u> -- I know these are depreciated, but my client wants them anyway).

Cheers,

tedd

_____________________
***@sperling.com
http://sperling.com
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Frank Arensmeier
2013-07-20 21:34:13 UTC
Permalink
Post by Tedd Sperling
I've been using
$str = strip_tags($str, $allowable)
http://php.net/manual/en/function.strip-tags.php
The problem I've found is the tags "<br>" and "<br />" are not stripped.
How do you strip all tags, but leave some tags (such as <b>, <i>, and <u> -- I know these are depreciated, but my client wants them anyway).
From the manual:
allowable_tags
You can use the optional second parameter to specify tags which should not be stripped.

Note:
HTML comments and PHP tags are also stripped. This is hardcoded and can not be changed with allowable_tags.

Note:
This parameter should not contain whitespace. strip_tags() sees a tag as a case-insensitive string between < and the first whitespace or >. It means that strip_tags("<br/>", "<br>") returns an empty string.

It's all there… ;-)

Cheers,
/frank
Post by Tedd Sperling
Cheers,
tedd
_____________________
http://sperling.com
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Tedd Sperling
2013-07-21 00:52:47 UTC
Permalink
Post by Frank Arensmeier
Post by Tedd Sperling
I've been using
$str = strip_tags($str, $allowable)
http://php.net/manual/en/function.strip-tags.php
The problem I've found is the tags "<br>" and "<br />" are not stripped.
How do you strip all tags, but leave some tags (such as <b>, <i>, and <u> -- I know these are depreciated, but my client wants them anyway).
allowable_tags
You can use the optional second parameter to specify tags which should not be stripped.
HTML comments and PHP tags are also stripped. This is hardcoded and can not be changed with allowable_tags.
This parameter should not contain whitespace. strip_tags() sees a tag as a case-insensitive string between < and the first whitespace or >. It means that strip_tags("<br/>", "<br>") returns an empty string.
It's all there… ;-)
Cheers,
/frank
Yeah, but that wasn't the problem -- it was my mistake in coding.

In any event, I figured it out.

tedd


_____________________
***@sperling.com
http://sperling.com
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Matijn Woudt
2013-07-21 19:46:39 UTC
Permalink
Post by Tedd Sperling
Post by Frank Arensmeier
Post by Tedd Sperling
I've been using
$str = strip_tags($str, $allowable)
http://php.net/manual/en/function.strip-tags.php
The problem I've found is the tags "<br>" and "<br />" are not stripped.
How do you strip all tags, but leave some tags (such as <b>, <i>, and
<u> -- I know these are depreciated, but my client wants them anyway).
Post by Tedd Sperling
Post by Frank Arensmeier
allowable_tags
You can use the optional second parameter to specify tags which should not be stripped.
HTML comments and PHP tags are also stripped. This is hardcoded and can
not be changed with allowable_tags.
Post by Tedd Sperling
Post by Frank Arensmeier
This parameter should not contain whitespace. strip_tags() sees a tag
as a case-insensitive string between < and the first whitespace or >. It
means that strip_tags("<br/>", "<br>") returns an empty string.
Post by Tedd Sperling
Post by Frank Arensmeier
It's all there
 ;-)
Cheers,
/frank
Yeah, but that wasn't the problem -- it was my mistake in coding.
In any event, I figured it out.
tedd
Could you perhaps post what the problem was so that when someone searches
for it they will have the answer right here?

- Matijn

Loading...