Home >Backend Development >PHP Tutorial >求教,怎么判断是否是低字节
求教,如何判断是否是低字节?
<?php<br />header("content-type:text/html;charset=gbk");<br />$str="j这是ces测试dkfjdksj";<br /><br />function substr_gbk($str,$start,$end)<br />{<br /> $temp="";<br /> for($i=$start;$i<=$end;$i++)<br /> {<br /> if(ord($str{$i})>0xa0)<br /> {<br /> $temp.=substr($str,$i,2);<br /> $i++;<br /> }else<br /> {<br /> $temp.=substr($str,$i,1);<br /> }<br /> }<br /> return $temp;<br />}<br /><br />echo substr_gbk($str,1,10); //从高字节截取正常<br />echo substr_gbk($str,2,10); //从低字节截取出现乱码<br />?><br />