note 56082 added to function.strip-tags
| From: | daneel at neezine dot net | Date: | Tue, 23 Aug 2005 00:08:32 +0000 |
| Subject: | note 56082 added to function.strip-tags | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-94056@lists.php.net to get a copy of this message | ||
Remove attributes from a tag except the attributes specified, correction of cool routine from
joris878 (who seems don't work) + example.
When PHP will going to support this natively ?
Sorry for my english. Hope everybody understand.
--French--
Enlève des attributs d'une balise, sauf les attributs spécifiés dans un tableau.
C'est une correction et un exemple de mise en oeuvre du code (très utile) posté par joris878
qui ne semblait pas fonctionner en l'état.
Quand PHP supportera ceci de façon native ?
----------
<?
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=0; $i <= (count($attr) - 1 );$i++)
{
$long_val = strpos($img," ",strpos($img,$attr[$i]."=")) -
(strpos($img,$attr[$i]."=") + strlen($attr[$i]) + 1) ;
$val = substr($img, strpos($img,$attr[$i]."=") + strlen($attr[$i]) + 1,$long_val);
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;
}
$message = "<font size=\"10\" face=\"tahoma\"
color=\"#DD0000\" >salut</font>" ;
//on ne garde que la couleur
//we want only "color" attribute
$message = stripeentag($message,"font",array("color"));
echo $message ;
?>
----
Manual Page -- http://www.php.net/manual/en/function.strip-tags.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+56082
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+56082&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+56082&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+56082&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+56082&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+56082&report=yes&reason=non-english
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+56082&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+56082&report=yes
Search -- http://master.php.net/manage/user-notes.php