#20881 [Com]: strip_tags() option to change brackets
| From: | mark at seventhcycle dot net | Date: | Fri, 07 Feb 2003 06:32:31 +0000 |
| Subject: | #20881 [Com]: strip_tags() option to change brackets | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-32369@lists.php.net to get a copy of this message | ||
ID: 20881
Comment by: mark@seventhcycle.net
Reported By: mark@seventhcycle.net
Status: Bogus
Bug Type: Feature/Change Request
PHP Version: 4.3.0RC2
New Comment:
The only problem with strtr() is that I/we weren't wanting this to
translate for every tag out there...
For instance:
strip_tags($str, "<A><B><I><U>");
I was looking for something that would translate the characters if it
DID NOT match those above tags. If it does, they would be left alone.
Possibly a good compromise would be a callback function to determine
what happens to tags that don't match the tags listed.
Previous Comments:
------------------------------------------------------------------------
[2003-02-06 21:50:33] iliaa@php.net
Use strtr() it will be much faster then modifying strip_tags with the
suggested functionality.
strtr($your_string, array(">" => ">", "<" =>
"<"));
------------------------------------------------------------------------
[2002-12-09 17:58:47] mark@seventhcycle.net
Exactly :)
------------------------------------------------------------------------
[2002-12-09 15:55:17] pollita@php.net
Your example is inconsistent with your explanation. Does the following
look like the behavior you had in mind?
strip_tags("<b>hi</b><i>there</i>", "<b>",
"<", ">");
would have an output of:
<b>hi</b><i>there</i>
------------------------------------------------------------------------
[2002-12-07 13:37:08] mark@seventhcycle.net
#15972, which is open right now, had some good thoughts on how to
expand strip_tags...
My suggestion:
1. Add a third/fourth parameter to it that (if specified) says what to
change the brackets *to* instead of replacing them.
e.g.:
strip_tags("<b>hi</b><i>there</i>", "<b>",
"<", ">");
would have an output of:
<b>hi</b> <there>
The point of this is so that rather than strip away tags that are
invalid, a forum would be able to see code just fine.. Well, that, and
we'd be able to have brackets on the site without typing in the html
equivalent ;)
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=20881&edit=1