php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #20881 strip_tags() option to change brackets
Submitted: 2002-12-07 13:37 UTC Modified: 2003-02-06 21:50 UTC
Votes:2
Avg. Score:4.5 ± 0.5
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: mark at seventhcycle dot net Assigned:
Status: Not a bug Package: Feature/Change Request
PHP Version: 4.3.0RC2 OS:
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: mark at seventhcycle dot net
New email:
PHP Version: OS:

 

 [2002-12-07 13:37 UTC] mark at seventhcycle dot 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>", "&lt", "&gt");

would have an output of:

<b>hi</b> &lt;there&gt;

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 ;)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-12-09 15:55 UTC] 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>", "&lt;", "&gt;");

would have an output of:

<b>hi</b>&lt;i&gt;there&lt;/i&gt;
 [2002-12-09 17:58 UTC] mark at seventhcycle dot net
Exactly :)
 [2003-02-06 21:50 UTC] iliaa@php.net
Use strtr() it will be much faster then modifying strip_tags with the suggested functionality.

strtr($your_string, array(">" => "&gt;", "<" => "&lt;"));
 [2003-02-07 00:32 UTC] mark at seventhcycle dot net
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.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 22 06:01:30 2024 UTC