Esempio n. 1
0
function sjis2utf8($sjis,$RefCode=1) {
	if (!trim($sjis))
		return $sjis;
	$filename = "CP932.TXT";
	$tmp = file($filename);
	$codetable = array();
	while (list($key, $value) = each($tmp)) {
		list($ansikey,$ukey)=explode("\t",$value);
		$codetable[hexdec($ansikey)] = $ukey;
	}

	$ret = "";
	$utf8 = "";
	while ($sjis) {
		if (ord(substr($sjis, 0, 1)) > 127) {
			if (ord(substr($sjis, 0, 1)) >= 161 && ord(substr($sjis, 0, 1)) <= 223) {
				$this = substr($sjis, 0, 1);
				$sjis = substr($sjis, 1, strlen($sjis));
			}else{
				$this = substr($sjis, 0, 2);
				$sjis = substr($sjis, 2, strlen($sjis));
			}
			if (!$RefCode) {
				$ret .= u2utf8(hexdec($codetable[hexdec(bin2hex($this))]));
			}else{
				$ret .= "&#".hexdec($codetable[hexdec(bin2hex($this))]).";";
			}
		} else {
			$ret .= substr($sjis, 0, 1);
			$sjis = substr($sjis, 1, strlen($sjis));
		}
	}
	return $ret;
}
Esempio n. 2
0
function gb2utf8($gb)
{
    if (!trim($gb)) {
        return $gb;
    }
    $filename = "gb2312.txt";
    $tmp = file($filename);
    $codetable = array();
    while (list($key, $value) = each($tmp)) {
        $codetable[hexdec(substr($value, 0, 6))] = substr($value, 7, 6);
    }
    $ret = "";
    $utf8 = "";
    while ($gb) {
        if (ord(substr($gb, 0, 1)) > 127) {
            $the = substr($gb, 0, 2);
            $gb = substr($gb, 2, strlen($gb));
            $utf8 = u2utf8(hexdec($codetable[hexdec(bin2hex($the)) - 0x8080]));
            for ($i = 0; $i < strlen($utf8); $i += 3) {
                $ret .= chr(substr($utf8, $i, 3));
            }
        } else {
            $ret .= substr($gb, 0, 1);
            $gb = substr($gb, 1, strlen($gb));
        }
    }
    return $ret;
}
Esempio n. 3
0
function gb2utf8($gbstr) {
	if(function_exists('iconv')){ return iconv('gbk','utf-8',$gbstr); }
	global $CODETABLE;
	if(trim($gbstr)=="") return $gbstr;
	if(empty($CODETABLE)){
		$filename = dirname(__FILE__)."/data/gb-utf8.table";
		$fp = fopen($filename,"r");
		while ($l = fgets($fp,15))
		{ $CODETABLE[hexdec(substr($l, 0, 4))] = substr($l, 5, 4); }
		fclose($fp);
	}
	$ret = "";
	$utf8 = "";
	while ($gbstr!='') {
		if (ord(substr($gbstr, 0, 1)) > 0x80) {
			$thisW = substr($gbstr, 0, 2);
			$gbstr = substr($gbstr, 2, strlen($gbstr));
			$utf8 = "";
			@$utf8 = u2utf8(hexdec($CODETABLE[hexdec(bin2hex($thisW)) - 0x8080]));
			if($utf8!=""){
				for ($i = 0;$i < strlen($utf8);$i += 3)
					$ret .= chr(substr($utf8, $i, 3));
			}
		}
		else
		{
			$ret .= substr($gbstr, 0, 1);
			$gbstr = substr($gbstr, 1, strlen($gbstr));
		}
	}
	return $ret;
}
Esempio n. 4
0
function utf8Encode($source)
{
    $utf8Str = $utf8val = '';
    $entityArray = explode('&#', $source);
    $size = count($entityArray);
    for ($i = 0; $i < $size; $i++) {
        $utf8Substring = '';
        $subStr = $entityArray[$i];
        $nonEntity = strstr($subStr, ';');
        if ($nonEntity !== false) {
            $unicode = intval(substr($subStr, 0, strpos($subStr, ';') + 1));
            // determine how many chars are needed to reprsent this unicode char
            $utf8Substring .= u2utf8($unicode);
            #			for ($y = 0;$y < strlen($utf8val);$y += 3)
            #				$utf8Substring .= chr(substr($utf8val, $y, 3));
            if (strlen($nonEntity) > 1) {
                $nonEntity = substr($nonEntity, 1);
            } else {
                $nonEntity = '';
            }
            $utf8Str .= $utf8Substring . $nonEntity;
        } else {
            $utf8Str .= $subStr;
        }
    }
    return $utf8Str;
}
Esempio n. 5
0
function gb2utf8($gb, $RefCode = 1)
{
    if (!trim($gb)) {
        return $gb;
    }
    $codepagefile = "CP936.TXT";
    $codepagesld = "CP936.SLD";
    if (file_exists($codepagesld)) {
        $codetable = unserialize(implode('', file($codepagesld)));
    } else {
        $tmp = file($codepagefile);
        $codetable = array();
        while (list($key, $value) = each($tmp)) {
            list($ansikey, $ukey) = explode("\t", trim($value));
            $codetable[hexdec($ansikey)] = $ukey;
        }
        unset($tmp);
        $rp = fopen($codepagesld, "w");
        @fputs($rp, serialize($codetable));
        fclose($rp);
        chmod($codepagesld, 0666);
    }
    $ret = "";
    $utf8 = "";
    while ($gb) {
        if (ord(substr($gb, 0, 1)) > 127) {
            if (ord(substr($gb, 0, 1)) == 128) {
                $curr = substr($gb, 0, 1);
                $gb = substr($gb, 1, strlen($gb));
            } else {
                $curr = substr($gb, 0, 2);
                $gb = substr($gb, 2, strlen($gb));
            }
            $char = hexdec(bin2hex($curr));
            $char = isset($codetable[$char]) ? $codetable[$char] : '20';
            if (!$RefCode) {
                $ret .= u2utf8(hexdec($char));
            } else {
                $ret .= "&#" . hexdec($char) . ";";
            }
        } else {
            $ret .= substr($gb, 0, 1);
            $gb = substr($gb, 1, strlen($gb));
        }
    }
    return $ret;
}
Esempio n. 6
0
function utf82u($str, $RefCode = 1)
{
    $unicode = array();
    $values = array();
    $lookingFor = 1;
    for ($i = 0; $i < strlen($str); $i++) {
        $thisValue = ord($str[$i]);
        if ($thisValue < 128) {
            $unicode[] = $thisValue;
        } else {
            if (count($values) == 0) {
                $lookingFor = $thisValue < 224 ? 2 : 3;
            }
            $values[] = $thisValue;
            if (count($values) == $lookingFor) {
                $number = $lookingFor == 3 ? $values[0] % 16 * 4096 + $values[1] % 64 * 64 + $values[2] % 64 : $values[0] % 32 * 64 + $values[1] % 64;
                $unicode[] = $number;
                $values = array();
                $lookingFor = 1;
            }
            // if
        }
        // if
    }
    // for
    if ($RefCode) {
        $entities = '';
        foreach ($unicode as $value) {
            $entities .= $value > 127 ? '&#' . $value . ';' : chr($value);
        }
        return $entities;
    } else {
        $wchars = '';
        foreach ($unicode as $value) {
            $wchars .= u2utf8($value);
        }
        return $wchars;
    }
}
Esempio n. 7
0
function jsUCEsc2utf8($str)
{
    preg_match_all('/%u([0-9A-Fa-f]{4})/', $str, $m);
    foreach ($m[1] as $uc) {
        $str = str_replace("%u{$uc}", u2utf8(hexdec($uc)), $str);
    }
    return $str;
}
Esempio n. 8
0
function gb2utf8($gbstr)
{
    global $CODETABLE, $ODBC;
    if (function_exists('header')) {
        header("Content-Type:text/html;charset={$ODBC['charset']}");
        return $gbstr;
    } else {
        if (M_B == true) {
            $ret = mb_convert_encoding($gbstr, 'utf-8', $ODBC['charset']);
        } else {
            if (ICONV == true) {
                $ret = iconv($ODBC['charset'], "UTF-8", $gbstr);
            } else {
                if (trim($gbstr) == "") {
                    return $gbstr;
                }
                if (empty($CODETABLE)) {
                    //$filename = dirname(__FILE__)."/gb2312-utf8.table";
                    $filename = R_P . "gb2312-utf8.table";
                    $fp = fopen($filename, "r");
                    while ($l = fgets($fp, 15)) {
                        $CODETABLE[hexdec(substr($l, 0, 6))] = substr($l, 7, 6);
                    }
                    fclose($fp);
                }
                $ret = "";
                $utf8 = "";
                while ($gbstr) {
                    if (ord(substr($gbstr, 0, 1)) > 127) {
                        $thisW = substr($gbstr, 0, 2);
                        $gbstr = substr($gbstr, 2, strlen($gbstr));
                        $utf8 = "";
                        $utf8 = u2utf8(hexdec($CODETABLE[hexdec(bin2hex($thisW)) - 0x8080]));
                        if ($utf8 != "") {
                            for ($i = 0; $i < strlen($utf8); $i += 3) {
                                $ret .= chr(substr($utf8, $i, 3));
                            }
                        }
                    } else {
                        $ret .= substr($gbstr, 0, 1);
                        $gbstr = substr($gbstr, 1, strlen($gbstr));
                    }
                }
            }
        }
    }
    return $ret;
}
Esempio n. 9
0
 function local2utf($string, $encoding)
 {
     global $lencodingtable;
     //                echo ;
     if (!trim($string)) {
         return $string;
     }
     if (!isset($lencodingtable[$encoding])) {
         $filename = realpath(dirname(__FILE__) . "/coding/" . $encoding . ".txt");
         if (!file_exists($filename) || $filename == "") {
             return $string;
         }
         $tmp = file($filename);
         $codetable = array();
         while (list($key, $value) = each($tmp)) {
             $codetable[hexdec(substr($value, 0, 6))] = hexdec(substr($value, 7, 6));
         }
         $lencodingtable[$encoding] = $codetable;
     } else {
         $codetable = $lencodingtable[$encoding];
     }
     $ret = "";
     while (strlen($string) > 0) {
         if (ord(substr($string, 0, 1)) > 127) {
             $t = substr($string, 0, 2);
             $string = substr($string, 2);
             $ret .= u2utf8($codetable[hexdec(bin2hex($t))]);
         } else {
             $t = substr($string, 0, 1);
             $string = substr($string, 1);
             $ret .= u2utf8($t);
         }
     }
     return $ret;
 }
Esempio n. 10
0
            array_push($s_obj, $data);
            // dump($data);
        } else {
            //补全归类 不需要显示wyong
            /**$nodata = array(
               'type_id' => $val,
               'name' => getTypeName($data_type,$val),
               'price' => 0,
               'fmt_price' => 0,
               'count' => 0
               );
               array_push($s_obj,$nodata);**/
        }
    }
    $arr = array_sort($s_obj, 'count', 'desc');
    echo '{"statistics":' . u2utf8(json_encode($arr)) . '}';
});
/**
 * 根据日期 按月份获取需求细分分类占比数据
 */
$app->get('/statismoney/:start/:end/:rank_cate_id', function ($start, $end, $rank_cate_id = 0) use($app) {
    getStaticsDataBycateId($start, $end, $rank_cate_id);
});
/**
 * 根据日期 按月份获取需求归档占比数据
 */
$app->get('/statistics/rank/:start/:end/:rank_id/:rank_type_id', function ($start, $end, $rank_id = 0) use($app) {
    $data = getStatisticsData($start, $end);
    $data_req = $data['require'];
    $data_type = $data['type'];
    $data_rank = $data['rank'];
Esempio n. 11
0
        } else {
            if ($c < 0x10000) {
                $str .= 0xe0 | $c >> 12;
                $str .= 0x80 | $c >> 6 & 0x3f;
                $str .= 0x80 | $c & 0x3f;
            } else {
                if ($c < 0x200000) {
                    $str .= 0xf0 | $c >> 18;
                    $str .= 0x80 | $c >> 12 & 0x3f;
                    $str .= 0x80 | $c >> 6 & 0x3f;
                    $str .= 0x80 | $c & 0x3f;
                }
            }
        }
    }
    for ($i = 0; $i < strlen($str); $i += 3) {
        $ret .= chr(substr($str, $i, 3));
    }
    return $ret;
}
$filename = @$_SERVER['argv'][1];
$tmp = file($filename) or die('file cannot be opened.');
$codetable = array();
while (list($key, $value) = each($tmp)) {
    list($ansikey, $ukey) = explode("\t", $value);
    $u = rtrim($ukey);
    if ($u) {
        $u = u2utf8(hexdec($u));
        echo "{$ansikey}\t{$u}\n";
    }
}
Esempio n. 12
0
function gb2utf8($gb)
{
    if (!trim($gb)) {
        return $gb;
    }
    $filename = "gb2312.txt";
    $tmp = file($filename);
    $codetable = array();
    while (list($key, $value) = each($tmp)) {
        $codetable[hexdec(substr($value, 0, 6))] = substr($value, 7, 6);
    }
    $utf8 = "";
    while ($gb) {
        if (ord(substr($gb, 0, 1)) > 127) {
            $tthis = substr($gb, 0, 2);
            $gb = substr($gb, 2, strlen($gb) - 2);
            $utf8 .= u2utf8(hexdec($codetable[hexdec(bin2hex($tthis)) - 0x8080]));
        } else {
            $tthis = substr($gb, 0, 1);
            $gb = substr($gb, 1, strlen($gb) - 1);
            $utf8 .= u2utf8($tthis);
        }
    }
    return $utf8;
}
Esempio n. 13
0
function elog($logstr, $type = 'info', $dir = "../logs/")
{
    $startweek = date('Y-m-d', time());
    $log = new KLogger($dir . $startweek . ".txt", KLogger::INFO);
    $user = getSessionUser();
    $str = u2utf8('(' . $user . ') ' . $logstr);
    switch ($type) {
        case 'error':
            $log->LogError($str);
            break;
        default:
            $log->LogInfo($str);
            break;
    }
}