note 48085 added to function.mb-decode-numericentity
| From: | AndrewSimpson at osu1 dot php dot net | Date: | Sat, 11 Dec 2004 01:29:14 +0000 |
| Subject: | note 48085 added to function.mb-decode-numericentity | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-81669@lists.php.net to get a copy of this message | ||
Many web browsers will tend upload high order characters as UTF-8 encoded entities.
Here is some simple code to convert UTF-8 HTML entities within a block of text into proper
characters:
<?php
//decode decimal HTML entities added by web browser
$body = preg_replace('/&#\d{2,5};/ue',
"utf8_entity_decode('$0')", $body );
//decode hex HTML entities added by web browser
$body = preg_replace('/&#x([a-fA-F0-7]{2,8});/ue',
"utf8_entity_decode('&#'.hexdec('$1').';')", $body );
//callback function for the regex
function utf8_entity_decode($entity){
$convmap = array(0x0, 0x10000, 0, 0xfffff);
return mb_decode_numericentity($entity, $convmap, 'UTF-8');
}
?>
----
Manual Page -- http://www.php.net/manual/en/function.mb-decode-numericentity.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+48085
Delete -- http://master.php.net/manage/user-notes.php?action=delete+48085&report=yes
Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+48085&report=yes&reason=bad+code
Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+48085&report=yes&reason=spam
Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+48085&report=yes&reason=useless+example
Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+48085&report=yes&reason=contains+commercial+links
Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+48085&report=yes&reason=useless+note
Reject -- http://master.php.net/manage/user-notes.php?action=reject+48085&report=yes
Search -- http://master.php.net/manage/user-notes.php