note 65880 added to function.strip-tags
| From: | xyexz at yahoo dot com | Date: | Tue, 09 May 2006 15:41:22 +0000 |
| Subject: | note 65880 added to function.strip-tags | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-110959@lists.php.net to get a copy of this message | ||
I have found with this function that sometimes it will only remove the first carrot from a tag and
leave the rest of the tag in the string, which obviously isn't what I'm looking for.
EX:
<?php
//Returns "tag>test/tag>"
echo strip_tags("<tag>test</tag>");
?>
I'm trying to strip_tags on a string I'm importing from xml so perhaps it has something to
do with that but if you've run into this same issue I've written a function to fix it once
and for all!
<?php
function theRealStripTags($string)
{
//while there are tags left to remove
while(strstr($string, '>'))
{
//find position of first carrot
$currentBeg = strpos($string, '<');
//find position of end carrot
$currentEnd = strpos($string, '>');
//find out if there is string before first carrot
//if so save it in $tmpstring
$tmpStringBeg = @substr($string, 0, $currentBeg);
//find out if there is string after last carrot
//if so save it in $tmpStringEnd
$tmpStringEnd = @substr($string, $currentEnd + 1, strlen($string));
//cut the tag from the string
$string = $tmpStringBeg.$tmpStringEnd;
}
return $string;
}
//Returns "test"
echo theRealStripTags('<tag>test</tag>');
?>
----
Server IP: 66.163.161.117
Probable Submitter: 66.194.50.2
----
X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER
autolearn=no version=2.64
----
Manual Page -- http://www.php.net/manual/en/function.strip-tags.php
Edit -- http://master.php.net/note/edit/65880
Del: integrated -- http://master.php.net/note/delete/65880/integrated
Del: useless -- http://master.php.net/note/delete/65880/useless
Del: bad code -- http://master.php.net/note/delete/65880/bad+code
Del: spam -- http://master.php.net/note/delete/65880/spam
Del: non-english -- http://master.php.net/note/delete/65880/non-english
Del: in docs -- http://master.php.net/note/delete/65880/in+docs
Del: other reasons-- http://master.php.net/note/delete/65880
Reject -- http://master.php.net/note/reject/65880
Search -- http://master.php.net/manage/user-notes.php