开发者

iconv equvalent of mb_string functions

开发者 https://www.devze.com 2023-01-30 01:55 出处:网络
I have the next sequence of code: // characters U-00000080 - U-000007FF, mask 110XXXXX $char= pack(\'C*\', $ord_v, ord($string{$c + 1}));

I have the next sequence of code:

// characters U-00000080 - U-000007FF, mask 110XXXXX
$char= pack('C*', $ord_v, ord($string{$c + 1}));
$c += 1;
$utf16= mb_convert_encoding($char, 'UTF-16', 'UTF-8');
$ret .= sprintf('\u%04s', bin2hex($utf16));

The code is part of json encode function from json.org. What is the equivalent iconv conversion to achive the same thing? I tried iconv('UTF-8',开发者_JAVA百科 'UTF-16', $char); but iconv inserts a LE flag byte (I guess), and I don't know how to deal with it.

Regards, Alex


iconv('UTF-8', 'UTF-16', '$char') converts the string "$char". To convert the content of the variable $char omit the apostrophes. iconv('UTF-8', 'UTF-16', $char)

0

精彩评论

暂无评论...
验证码 换一张
取 消