中文如何转换为bytes[]

WBOY
Release: 2016-06-13 12:21:03
Original
1199 people have browsed it

中文怎么转换为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);
Copy after login
Array<br />(<br />    [0] => 229<br />    [1] => 185<br />    [2] => 191<br />    [3] => 228<br />    [4] => 184<br />    [5] => 156<br />)<br /><br />
Copy after login

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

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template