note 96194 added to function.strip-tags
| From: | MatthieuLarcher at osu1 dot php dot net | Date: | Sat, 13 Feb 2010 14:34:41 +0000 |
| Subject: | note 96194 added to function.strip-tags | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-165935@lists.php.net to get a copy of this message | ||
I found the function given by Mehul to enhance the basic strip_tags very useful.
However, it alters the content : we don't necessarily want all non tag-opening "<"
to be replaced by "<"
Here is a version that will return the exact same content as the input, minus the tags :
function enhanced_strip_tags( $content )
{
$parts = explode( '<', $content );
$result = $parts[0];
for( $i = 1; $i < count($parts); $i++ )
{
if( !strpos( $parts[$i], '>' ) ){
$result = $result . '¤<¤' . $parts[$i];
} else {
$result = $result . '<' . $parts[$i];
}
}
return str_replace( '¤<¤', '<', strip_tags( $result ) );
}
Note that I used dummy "¤" characters to avoid the unwanted replacement of
"<" that belonged to the content in the first place.
The intent here is only to have something unique as a placeholder for non tag-opening
"<".
This may pose problems if utf-8 is not handled, so feel free to use whatever you want instead.
----
Server IP: 69.147.83.197
Probable Submitter: 82.239.72.190
----
Manual Page -- http://www.php.net/manual/en/function.strip-tags.php
Edit -- https://master.php.net/note/edit/96194
Del: integrated -- https://master.php.net/note/delete/96194/integrated
Del: useless -- https://master.php.net/note/delete/96194/useless
Del: bad code -- https://master.php.net/note/delete/96194/bad+code
Del: spam -- https://master.php.net/note/delete/96194/spam
Del: non-english -- https://master.php.net/note/delete/96194/non-english
Del: in docs -- https://master.php.net/note/delete/96194/in+docs
Del: other reasons-- https://master.php.net/note/delete/96194
Reject -- https://master.php.net/note/reject/96194
Search -- https://master.php.net/manage/user-notes.php