Exemple #1
0
function change2pinyin($str, $type = '')
{
    $ret = "";
    if (WEB_LANG == 'utf-8') {
        if (function_exists('iconv')) {
            $str = iconv('UTF-8', 'GBK//IGNORE', $str);
        } else {
            require_once ROOT_PATH . "inc/class.chinese.php";
            $cnvert = new Chinese("UTF8", "GB2312", $str, ROOT_PATH . "./inc/gbkcode/");
            $str = $cnvert->ConvertIT();
        }
    } elseif (WEB_LANG == 'big5') {
        require_once ROOT_PATH . "inc/class.chinese.php";
        $cnvert = new Chinese("BIG5", "GB2312", $str, ROOT_PATH . "./inc/gbkcode/");
        $str = $cnvert->ConvertIT();
    }
    for ($i = 0; $i < strlen($str); $i++) {
        $p = ord(substr($str, $i, 1));
        if ($p > 160) {
            $q = ord(substr($str, ++$i, 1));
            $p = $p * 256 + $q - 65536;
        }
        $ret .= GetPinYin($p, $type);
    }
    return $ret;
}
Exemple #2
0
function change2pinyin($str, $type = '')
{
    $ret = "";
    for ($i = 0; $i < strlen($str); $i++) {
        $p = ord(substr($str, $i, 1));
        if ($p > 160) {
            $q = ord(substr($str, ++$i, 1));
            $p = $p * 256 + $q - 65536;
        }
        $ret .= GetPinYin($p, $type);
    }
    return $ret;
}