Home >php教程 >php手册 >按字节截取文本,中英文混合不乱码

按字节截取文本,中英文混合不乱码

WBOY
WBOYOriginal
2016-06-07 11:40:041564browse

保持最大长度,且文字完整
只支持GBK,UTF8的先转GBK再执行

function gbk_left($str,$len){<br>         if(strlen($str)         $txt='';<br>         for($i=0;$i             if(ord($str{$i})>0x80){<br>                 if($i+1==$len) return $txt;<br>                 $txt.=$str{$i}.$str{$i+1};<br>                 $i++;<br>                 continue;<br>             }<br>             $txt.=$str{$i};<br>         }<br>         return $txt;<br>     }

AD:真正免费,域名+虚机+企业邮箱=0元

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