PHP将字符串转成NCR编码

回复 星标
更多
PHP将字符串转成NCR编码
.
.
.
.
.
.
function nochaoscode($encode, $str, $isemail = false) {
        $output = '';
        $str = iconv($encode, "UTF-16", $str);
        for ($i = 0; $i < strlen($str); $i++,$i++) {
            $code = ord($str{$i}) * 256 + ord($str{$i + 1});
            if ($code < 128 and !$isemail) {
                $output .= chr($code);
            } else if ($code != 65279) {
                $output .= "&#".$code.";";
            }
        }
        return $output;
    }
新窗口打开 关闭