note 45079 deleted from function.htmlentities by tomsommer
| From: | tomsommer@php.net | Date: | Wed, 25 Aug 2004 21:37:22 +0000 |
| Subject: | note 45079 deleted from function.htmlentities by tomsommer | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-75259@lists.php.net to get a copy of this message | ||
Note Submitter: thenderson at cromwells dot co dot uk
----
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