php将中文转成byte的方法:1、创建一个php示例文件;2、通过“function stringtobytearray($str,$charset) {...}”方法将中文转成byte数组即可。
本文操作环境:windows7系统、php7.1版、dell g3电脑
php 怎么将中文转成byte?
php汉字 字节数组转换
<?phpfunction stringtobytearray($str,$charset) {     $str = iconv($charset,'utf-16',$str);    preg_match_all('/(.)/s',$str,$bytes);  //注:本文的盗版已经有了。不过,提示一下读者,这里的正则改了。    $bytes=array_map('ord',$bytes[1]) ;    return $bytes; } function bytearraytostring($bytes,$charset) {     $bytes=array_map('chr',$bytes);    $str=implode('',$bytes);    $str = iconv('utf-16',$charset,$str);    return $str; } $bytearray=stringtobytearray('13亿人口大国,自认为精通php的还是相当多的!','utf-8');print_r($bytearray);$retstr=bytearraytostring($bytearray,'utf-8');echo $retstr; ?>
推荐学习:《php视频教程》
以上就是php 怎么将中文转成byte的详细内容。
   
 
   