Heim > Artikel > Backend-Entwicklung > 中文如何转换为bytes[]
中文怎么转换为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 />