note 32679 deleted from function.strip-tags by ezyang
| From: | ezyang@php.net | Date: | Tue, 05 Aug 2008 16:22:01 +0000 |
| Subject: | note 32679 deleted from function.strip-tags by ezyang | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-143170@lists.php.net to get a copy of this message | ||
Note Submitter: joris878 at hotmail dot com
----
[ Editor's Note: This functionality will be natively supported in a future release of PHP.
Most likely 5.0 ]
This routine removes all attributes from a given tag except
the attributes specified in the array $attr.
function stripeentag($msg,$tag,$attr) {
$lengthfirst = 0;
while (strstr(substr($msg,$lengthfirst),"<$tag ")!="")
{
$imgstart = $lengthfirst + strpos(substr($msg,$lengthfirst), "<$tag ");
$partafterwith = substr($msg,$imgstart);
$img = substr($partafterwith,0,strpos($partafterwith,">")+1);
$img = str_replace(" =","=",$msg);
$out = "<$tag";
for($i=1;$i<=count($atr);$i++)
{
$val = filter($img,$attr[$i]."="," ");
if(strlen($val)>0) $attr[$i] = " ".$attr[$i]."=".$val;
else $attr[$i] = "";
$out .= $attr[$i];
}
$out .= ">";
$partafter = substr($partafterwith,strpos($partafterwith,">")+1);
$msg = substr($msg,0,$imgstart).$out.$partafter;
$lengthfirst = $imgstart+3;
}
return $msg;
}