note 45079 added to function.htmlentities
| From: | thenderson at cromwells dot co dot uk | Date: | Wed, 25 Aug 2004 16:27:05 +0000 |
| Subject: | note 45079 added to function.htmlentities | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-75247@lists.php.net to get a copy of this message | ||
It seems a lot of folk have been looking for a function to convert character entities to their
*numeric* equivalents, but the only solution I'd seen was to use mb_encode_numericentity, but
that's not easy for us to switch on, so here's a simple alternative which uses urlencode
to convert the entities to numbers, then uses preg_replace to wrap them in the &#x..;
//=======================
// html_numeric_entities
//--------------------------------------------------------
// Convert all applicable characters to HTML numeric entities.
//============================================
function html_numeric_entities($string) {
$string = urlencode($string);
$string = preg_replace('/(%)(..)/', '&#x\\2;', $string);
$string = str_replace('+', ' ', $string);
return $string;
}
Hope you find it useful!
Tim
http://www.web-bureau.com
----
Manual Page -- http://www.php.net/manual/en/function.htmlentities.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+45079
Delete -- http://master.php.net/manage/user-notes.php?action=delete+45079&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+45079&report=yes
Search -- http://master.php.net/manage/user-notes.php