note 51733 deleted from function.preg-match-all by felipe
| From: | felipe@php.net | Date: | Mon, 10 Dec 2007 02:01:02 +0000 |
| Subject: | note 51733 deleted from function.preg-match-all by felipe | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-133084@lists.php.net to get a copy of this message | ||
Note Submitter: b2sing4u at naver dot com
----
This function converts all HTML style decimal character code to hexadecimal code.
ex) Hi ο ◊ Dec -> Hi ο ◊ Dec
function d2h($word) {
$n = preg_match_all("/&#(\d+?);/", $word, $match, PREG_PATTERN_ORDER);
for ($j = 0; $j < $n; $j++) {
$word = str_replace($match[0][$j], sprintf("&#x%04X;", $match[1][$j]), $word);
}
return($word);
}
& This function converts all HTML style hexadecimal character code to decimal code.
ex) Hello ο ◊ Hex -> Hello ο ◊ Hex
function h2d($word) {
$n = preg_match_all("/&#x([0-9a-fA-F]+?);/", $word, $match, PREG_PATTERN_ORDER);
for ($j = 0; $j < $n; $j++) {
$word = str_replace($match[0][$j], sprintf("&#%u;", hexdec($match[1][$j])),
$word);
}
return($word);
}