note 56237 deleted from function.htmlentities by mazzanet
| From: | mazzanet@php.net | Date: | Mon, 03 Oct 2005 08:47:30 +0000 |
| Subject: | note 56237 deleted from function.htmlentities by mazzanet | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-96238@lists.php.net to get a copy of this message | ||
Note Submitter: greenthumb at 4point-webdesign dot de
----
if you need to htmlentity only the text-parts of a given html-string use the following function, in
the array put the attributes you want to be also html-ized
<?
function htmlenc($res) {
$res=preg_replace('#&[^ ;]+;#i','<\\0>',$res);
foreach(array('title','alt') as $k)
$res=preg_replace('#<([^<]*)
'.$k.'="([^"]*)"([^>]*)>#Uise', '"<\\1
'.$k.'=\"".htmlentities("\\2")."\"\\3>"',$res);
$res=preg_replace('#(^|>)([^<>]+)($|<)#Uise',
'"\\1".htmlentities("\\2")."\\3"',$res);
$res=preg_replace('#<(&[^ ;]+;)>#i','\\1',$res);
return $res;
}
?>