note 89309 modified in function.strip-tags by danbrown
| From: | danbrown@php.net | Date: | Tue, 03 Mar 2009 15:04:27 +0000 |
| Subject: | note 89309 modified in function.strip-tags by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-151394@lists.php.net to get a copy of this message | ||
Strip tags doesn't work fine if we have '<' symbol in the string followed
immediately by any letter. but it doed work fine if there is a space after '<' symbol.
e.g.
<?php
strip_tags('<p>1<4</p>'); //won't work fine
strip_tags('<p>1 < 4</p>'); //will work fine
?>
to solve this problem, I used a simple logic. This code will replace '<' by html char,
if it not a part of html tag.
My version of strip_tags is as follow:
<?php
function my_strip_tags($str) {
$strs=explode('<',$str);
$res=$strs[0];
for($i=1;$i<count($strs);$i++)
{
if(!strpos($strs[$i],'>'))
$res = $res.'<'.$strs[$i];
else
$res = $res.'<'.$strs[$i];
}
return strip_tags($res);
}
?>
--was--
Strip tags doesn't work fine if we have '<' symbol in the string followed
immediately by any letter. but it doed work fine if there is a space after '<' symbol.
e.g.
strip_tags('<p>1<4</p>'); //won't work fine
strip_tags('<p>1 < 4</p>'); //will work fine
to solve this problem, I used a simple logic. This code will replace '<' by html char,
if it not a part of html tag.
My version of strip_tags is as follow:
function my_strip_tags($str) {
$strs=explode('<',$str);
$res=$strs[0];
for($i=1;$i<count($strs);$i++)
{
if(!strpos($strs[$i],'>'))
$res = $res.'<'.$strs[$i];
else
$res = $res.'<'.$strs[$i];
}
return strip_tags($res);
}
http://php.net/manual/en/function.strip-tags.php