note 111859 added to function.html-entity-decode
| From: | Benjamin | Date: | Fri, 05 Apr 2013 11:07:23 +0000 |
| Subject: | note 111859 added to function.html-entity-decode | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-194346@lists.php.net to get a copy of this message | ||
The following function decodes named and numeric HTML entities and works on UTF-8. Requires iconv.
function decodeHtmlEnt($str) {
$ret = html_entity_decode($str, ENT_COMPAT, 'UTF-8');
$p2 = -1;
for(;;) {
$p = strpos($ret, '&#', $p2+1);
if ($p === FALSE)
break;
$p2 = strpos($ret, ';', $p);
if ($p2 === FALSE)
break;
if (substr($ret, $p+2, 1) == 'x')
$char = hexdec(substr($ret, $p+3, $p2-$p-3));
else
$char = intval(substr($ret, $p+2, $p2-$p-2));
//echo "$char\n";
$newchar = iconv(
'UCS-4', 'UTF-8',
chr(($char>>24)&0xFF).chr(($char>>16)&0xFF).chr(($char>>8)&0xFF).chr($char&0xFF)
);
//echo "$newchar<$p<$p2<<\n";
$ret = substr_replace($ret, $newchar, $p, 1+$p2-$p);
$p2 = $p + strlen($newchar);
}
return $ret;
}
----
Server IP: 69.147.83.199
Probable Submitter: 92.231.200.229
----
Manual Page -- http://php.net/manual/en/function.html-entity-decode.php
Edit -- https://master.php.net/note/edit/111859
Del: integrated -- https://master.php.net/note/delete/111859/integrated
Del: useless -- https://master.php.net/note/delete/111859/useless
Del: bad code -- https://master.php.net/note/delete/111859/bad+code
Del: spam -- https://master.php.net/note/delete/111859/spam
Del: non-english -- https://master.php.net/note/delete/111859/non-english
Del: in docs -- https://master.php.net/note/delete/111859/in+docs
Del: other reasons-- https://master.php.net/note/delete/111859
Reject -- https://master.php.net/note/reject/111859
Search -- https://master.php.net/manage/user-notes.php