note 60021 deleted from function.html-entity-decode by danbrown
| From: | danbrown@php.net | Date: | Tue, 10 Jan 2012 20:13:49 +0000 |
| Subject: | note 60021 deleted from function.html-entity-decode by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-185542@lists.php.net to get a copy of this message | ||
Note Submitter: hurricane at cyberworldz dot org
----
I shortened the function repace_num_entity a bit to make more understandable and clean. Maybe now
someone sees the problem it possibly has... (as mentioned below)
<?php
function replace_num_entity($ord) {
$ord = $ord[1];
if (preg_match('/^x([0-9a-f]+)$/i', $ord, $match)) $ord = hexdec($match[1]);
else $ord = intval($ord);
$no_bytes = 0;
$byte = array();
if ($ord < 128) return chr($ord);
if ($ord < 2048) $no_bytes = 2;
else if ($ord < 65536) $no_bytes = 3;
else if ($ord < 1114112) $no_bytes = 4;
else return;
switch($no_bytes) {
case 2: $prefix = array(31, 192); break;
case 3: $prefix = array(15, 224); break;
case 4: $prefix = array(7, 240);
}
for ($i=0; $i < $no_bytes; ++$i)
$byte[$no_bytes-$i-1] = (($ord & (63 * pow(2,6*$i))) / pow(2,6*$i)) & 63 | 128;
$byte[0] = ($byte[0] & $prefix[0]) | $prefix[1];
$ret = '';
for ($i=0; $i < $no_bytes; ++$i) $ret .= chr($byte[$i]);
return $ret;
}
?>