解决方案 »

  1.   


    echo mb_strlen("星",'gbk');1
      

  2.   

    echo strlen("星")输出的是3
    表示你的程序文件保存成了 utf-8 编码的了
      

  3.   

    在strlen计算时,对待一个UTF8的中文字符是3个长度
    这是固定值,不必理会为什么.
    因为我也不知道.
      

  4.   

    在utf-8编码下,一个汉字占3个字节,所以返回3.
      

  5.   


    <?php
    $str = '我';
    echo strlen($str).PHP_EOL;
    $encode = mb_detect_encoding($str, array("ASCII","UTF-8","GB2312","GBK","BIG5")); 
    echo $encode;
      

  6.   

    <meta http-equiv="content-type" content="textml; charset=gbk">
    echo strlen("星");我的不管是 utf-8 还是 gbk都是输出3
    重装后两个都是输出 2
    我彻底凌乱了
      

  7.   

    为什么
    echo mb_strlen("星",'gbk');   输出是1
    echo mb_strlen("星",‘utf-8’); 我输出的是1
     
      

  8.   

    echo strlen("星");
    怎样在utf-8下输出3
    在gbk下输出2
      

  9.   

    将你的文件保存为utf-8编码就是在utf-8下。保存为ANSI格式就是gbk下。
      

  10.   

    <meta http-equiv="content-type" content="textml; charset=gbk">
    不是这个编码,而是你的php文件保存时的编码。
    UTF8 中文是3个字符
    GBK 中文是2个字符
      

  11.   


    请问你这个软件叫什么名字,我也想下载
    我之前那些代码都是用Visual Studio 2013 写的,再把后缀名改为php,经常出现一些奇怪的问题
      

  12.   

    最后一个小疑问
    echo mb_strlen("星",'gbk');
    utf-8 下  输出  2
    ansi 下  输出 1echo mb_strlen("星",'utf-8');
    utf-8 下  输出  1
    ansi 下  输出 1这个是怎么一回事??
      

  13.   

    <meta http-equiv="content-type" content="textml; charset=gbk">
    不可以转码吗?
      

  14.   

    不可以!
    <meta http-equiv="content-type" content="textml; charset=gbk">
    只是通知浏览器用 charset 指定的字符集解释内容
    如果你的程序文件是 utf-8 的,那么声明 charset=gbk 只会导致乱码
    而没有 <meta http-equiv="content-type" content="textml; charset=gbk"> 反而会因浏览器的自动识别功能,不出现乱码
      

  15.   

    设置文件的编码和声明charset是不同的,如果需要设置文件编码,一般的软件就可以解决,如notepad++
      

  16.   

    echo mb_strlen("星",'gbk');
    utf-8 下  输出  2
    ansi 下  输出 1echo mb_strlen("星",'utf-8');
    utf-8 下  输出  1
    ansi 下  输出 1这个是怎么一回事??
      

  17.   


    请问你这个软件叫什么名字,我也想下载
    我之前那些代码都是用Visual Studio 2013 写的,再把后缀名改为php,经常出现一些奇怪的问题editplus
      

  18.   

    關於mb_strlen 可以看看這裡http://developer.51cto.com/art/201105/263103.htm
      

  19.   

    可以这样理解。
    echo mb_strlen("星",'gbk');
    utf-8 下  输出  2    //  一个中文在utf-8下占三个字节,在gbk下占两个字节, 以gbk算的话,就是3/2 = 1.5个字符,半个字符也算一个,所以输出2
    ansi 下  输出 1   echo mb_strlen("星",'utf-8');
    utf-8 下  输出  1 
    ansi 下  输出 1    // 这里就是2/3 小于1,也是按1算。所以用mb_strlen 检测字符串包含的字符数时,编码统一就不会有问题了。
      

  20.   

    不同的环境中出现了不同的结果,这是因为你错误的使用了参数造成的!
    mb 系列函数的 encoding 参数用于指明被操作的字符串的字符集,给错了自然结果也就错了
    所以在使用时应用 mb_detect_encoding 或 mb_check_encoding 函数取得字符串实际的字符集
    $s = '星';
    $charset = mb_detect_encoding($s, 'utf-8, gbk');
    echo mb_strlen($s, $charset);$charset = mb_check_encoding($s, 'utf-8') ? 'utf-8' : 'gbk';
    echo mb_strlen($s, $charset);由于 mb_detect_encoding 容易出现误判,所以新增了比较准确的 mb_check_encoding 函数