Home  >  Article  >  Backend Development  >  中文如何转换为bytes[]

中文如何转换为bytes[]

WBOY
WBOYOriginal
2016-06-13 12:21:031200browse

中文怎么转换为bytes[]
例如“广东”  转化成byte[]={[-27, -71, -65, -28, -72, -100]} 

用一个现成的函数还是要稍微编个函数
------解决思路----------------------

$s = "广东";<br />$s = iconv('gbk', 'utf-8', $s);<br />$r = array_map('ord', str_split($s));<br />print_r($r);
Array<br />(<br />    [0] => 229<br />    [1] => 185<br />    [2] => 191<br />    [3] => 228<br />    [4] => 184<br />    [5] => 156<br />)<br /><br />

------解决思路----------------------
$s = "广东";<br />$s = iconv('gbk', 'utf-8', $s);<br />$r = unpack('C*', $s);<br />print_r($r);
Array<br />(<br />    [1] => 229<br />    [2] => 185<br />    [3] => 191<br />    [4] => 228<br />    [5] => 184<br />    [6] => 156<br />)<br /><br />
$s = "广东";<br />$s = iconv('gbk', 'utf-8', $s);<br />$r = unpack('C*', $s);<br />print_r($r);
Array<br />(<br />    [1] => -27<br />    [2] => -71<br />    [3] => -65<br />    [4] => -28<br />    [5] => -72<br />    [6] => -100<br />)<br /><br />

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn