V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
mune
V2EX  ›  问与答

PHP 小弟求解释一段代码? iconv 函数我是知道的,但是其上的判断什么意思?

  •  
  •   mune · 2017-07-11 10:32:38 +08:00 · 938 次点击
    这是一个创建于 2509 天前的主题,其中的信息可能已经有所发展或是发生改变。
    /**
    * 转编码为 gb2312
    * @param string $pStr 字符串
    * @param string $pCharset 字符串编码
    *
    * @return string
    */
    static function str2gbk($pStr, $pCharset) {
    $tStr = '';
    if ($pStr < 0x80) {
    $tStr .= $pStr;
    }
    elseif ($pStr < 0x800) {
    $tStr .= chr(0xC0 | $pStr >> 6);
    $tStr .= chr(0x80 | $pStr & 0x3F);
    }
    elseif ($pStr < 0x10000) {
    $tStr .= chr(0xE0 | $pStr >> 12);
    $tStr .= chr(0x80 | $pStr >> 6 & 0x3F);
    $tStr .= chr(0x80 | $pStr & 0x3F);
    }
    elseif ($pStr < 0x200000) {
    $tStr .= chr(0xF0 | $pStr >> 18);
    $tStr .= chr(0x80 | $pStr >> 12 & 0x3F);
    $tStr .= chr(0x80 | $pStr >> 6 & 0x3F);
    $tStr .= chr(0x80 | $pStr & 0x3F);
    }
    return iconv($pCharset, 'GB2312', $tStr);
    }
    2 条回复
    linoder
        1
    linoder  
       2017-07-11 13:58:32 +08:00
    XML 实体
    snnn
        2
    snnn  
       2017-07-11 19:30:39 +08:00 via Android
    unicode 转 utf8
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   3145 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 10:39 · PVG 18:39 · LAX 03:39 · JFK 06:39
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.