note 27426 added to function.utf8-decode

From: Date: Thu, 05 Dec 2002 15:44:52 +0000
Subject: note 27426 added to function.utf8-decode
Groups: php.notes 
Request: Send a blank email to php-notes+get-40381@lists.php.net to get a copy of this message
Here is a function I made to convert all 2 byte utf in a &#xxx; form: function utf2html ($utf2html_string) { $utf2html_retstr = ""; for ($utf2html_p=0; $utf2html_p<strlen($utf2html_string); $utf2html_p++): $utf2html_c = substr ($utf2html_string, $utf2html_p, 1); $utf2html_c1 = ord ($utf2html_c); if ($utf2html_c1>>5 == 6): // 110x xxxx, 110 prefix for 2 bytes unicode $utf2html_p++; $utf2html_t = substr ($utf2html_string, $utf2html_p, 1); $utf2html_c2 = ord ($utf2html_t); $utf2html_c1 &= 31; // remove the 3 bit two bytes prefix $utf2html_c2 &= 63; // remove the 2 bit trailing byte prefix $utf2html_c2 |= (($utf2html_c1 & 3) << 6); // last 2 bits of c1 become first 2 of c2 $utf2html_c1 >>= 2; // c1 shifts 2 to the right $utf2html_n = dechex($utf2html_c1).dechex($utf2html_c2); $utf2html_retstr .= sprintf ("&#%03d;", hexdec($utf2html_n)); else: $utf2html_retstr .= $utf2html_c; endif; endfor; return $utf2html_retstr; } -- http://www.php.net/manual/en/function.utf8-decode.php http://master.php.net/manage/user-notes.php?action=edit+27426 http://master.php.net/manage/user-notes.php?action=delete+27426 http://master.php.net/manage/user-notes.php?action=reject+27426

« previous php.notes (#40381) next »