Exemplo n.º 1
0
/**
 * gbk转拼音
 * @param $txt
 */
function gbk_to_pinyin($txt)
{
    $txt = iconv('utf8', 'GBK', $txt);
    $l = strlen($txt);
    $i = 0;
    $pyarr = array();
    $py = array();
    $filename = 'gb-pinyin.table';
    $fp = fopen($filename, 'r');
    while (!feof($fp)) {
        $p = explode("-", fgets($fp, 32));
        $pyarr[intval($p[1])] = trim($p[0]);
    }
    fclose($fp);
    ksort($pyarr);
    while ($i < $l) {
        $tmp = ord($txt[$i]);
        if ($tmp >= 128) {
            $asc = abs($tmp * 256 + ord($txt[$i + 1]) - 65536);
            $i = $i + 1;
        } else {
            $asc = $tmp;
        }
        $py[] = asc_to_pinyin($asc, $pyarr);
        $i++;
    }
    return $py;
}
Exemplo n.º 2
0
function gbk_to_pinyin($_obfuscate_so7)
{
    $A = strlen($_obfuscate_so7);
    $_obfuscate_7wÿÿ = 0;
    $_obfuscate_0ZNCtmYÿ = array();
    $_obfuscate_r5Qÿ = array();
    $_obfuscate_JTe7jJ4eGW8ÿ = CODETABLEDIR . "gb-pinyin.table";
    $_obfuscate_YBYÿ = fopen($_obfuscate_JTe7jJ4eGW8ÿ, "r");
    while (!feof($_obfuscate_YBYÿ)) {
        $_obfuscate_8wÿÿ = explode("-", fgets($_obfuscate_YBYÿ, 32));
        $_obfuscate_0ZNCtmYÿ[intval($_obfuscate_8wÿÿ[1])] = trim($_obfuscate_8wÿÿ[0]);
    }
    fclose($_obfuscate_YBYÿ);
    ksort(&$_obfuscate_0ZNCtmYÿ);
    while ($_obfuscate_7wÿÿ < $A) {
        $_obfuscate_juwe = ord($_obfuscate_so7[$_obfuscate_7wÿÿ]);
        if (128 <= $_obfuscate_juwe) {
            $_obfuscate_Vikx = abs($_obfuscate_juwe * 256 + ord($_obfuscate_so7[$_obfuscate_7wÿÿ + 1]) - 65536);
            $_obfuscate_7wÿÿ += 1;
        } else {
            $_obfuscate_Vikx = $_obfuscate_juwe;
        }
        $_obfuscate_r5Qÿ[] = asc_to_pinyin($_obfuscate_Vikx, &$_obfuscate_0ZNCtmYÿ);
        ++$_obfuscate_7wÿÿ;
    }
    return $_obfuscate_r5Qÿ;
}