note 49171 added to function.iconv

From: Date: Tue, 18 Jan 2005 23:02:11 +0000
Subject: note 49171 added to function.iconv
Groups: php.notes 
Request: Send a blank email to php-notes+get-83591@lists.php.net to get a copy of this message
Here is how to convert UCS-2 numbers to UTF-8 numbers in hex: function ucs2toutf8($str) { for ($i=0;$i<strlen($str);$i+=4) { $substring1 = $str[$i].$str[$i+1]; $substring2 = $str[$i+2].$str[$i+3]; if ($substring1 == "00") { $byte1 = ""; $byte2 = $substring2; } else { $substring = $substring1.$substring2; $byte1 = dechex(192+(hexdec($substring)/64)); $byte2 = dechex(128+(hexdec($substring)%64)); } $utf8 .= $byte1.$byte2; } return $utf8; } echo strtoupper(ucs2toutf8("06450631062D0020")); ?> Input: 06450631062D Output: D985D8B1D8AD regards, Ziyad ---- Manual Page -- http://www.php.net/manual/en/function.iconv.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+49171 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+49171&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+49171&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+49171&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+49171&report=yes&reason=useless Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+49171&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+49171&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#83591) next »