截取GBK字符串的有关问题~

WBOY
Release: 2016-06-13 13:27:35
Original
892 people have browsed it

截取GBK字符串的问题~~~~
这是一个截取GBK字符串的函数:

PHP code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->
function  gb_substr( $str ,  $len ){        
      $count  = 0;        
      for ( $i =0;  $i 
Copy after login


我的问题是,GBK和GB2312每个字符不肯定是2个字节吗?那直接用要截取的长度*2不完了吗?
比如我要截取3个字符:3*2=6 也就是我要截取到6的位置。

这么想对吗?

------解决方案--------------------
使用mb系列函数,GBK对非ASCII两个字符,ASCII还是1个字节。
------解决方案--------------------
不对,因为有可能含ascii码的数字或字符

探讨
这是一个截取GBK字符串的函数:
PHP code

function gb_substr( $str , $len ){
$count = 0;
for ( $i =0; $i if ( $count == $len ) break……
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