note 51733 added to function.preg-match-all

From: Date: Fri, 08 Apr 2005 22:42:05 +0000
Subject: note 51733 added to function.preg-match-all
Groups: php.notes 
Request: Send a blank email to php-notes+get-87725@lists.php.net to get a copy of this message
This function converts all HTML style decimal character code to hexadecimal code. ex) Hi &#959; &#9674; Dec -> Hi &#x03BF; &#x25CA; 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 &#x03BF; &#x25CA; Hex -> Hello &#959; &#9674; 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); } ---- Manual Page -- http://www.php.net/manual/en/function.preg-match-all.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+51733 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+51733&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+51733&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+51733&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+51733&report=yes&reason=useless Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+51733&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+51733&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#87725) next »