<?php
function unescape($source, $iconv_to = 'UTF-8') {
$decodedStr = '';
$pos = 0;
$len = strlen($source);
while ( $pos < $len ) {
$charAt = substr($source , $pos , 1);
if($charAt == '//') {
$pos++;
$charAt = substr($source , $pos , 1);
if($charAt == 'u') {
$pos++;
$unicodeHexVal = substr($source , $pos , 4);
$unicode = hexdec($unicodeHexVal);
$decodedStr .= code2utf($unicode);
$pos += 4;
} else {
$hexVal = substr($source , $pos , 2);
$decodedStr .= chr(hexdec($hexVal));
$pos += 2;
}
} else {
$decodedStr .= $charAt;
$pos++;
}
}
if($iconv_to != "UTF-8") {
$decodedStr = iconv("UTF-8" , $iconv_to , $decodedStr);
}
return $decodedStr;
}
function code2utf($num) {
if($num < 128) return chr($num);
if($num < 2048) return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
if($num < 65536) return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
if($num < 2097152) return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
return '';
}
$file_name = "piao.sort";
$file = file($file_name);
$data_array = array();
foreach($file as $line)
{
//ECHO (DEBUG_LOG,"TRACE : line to array /n",__FILE__,__FUNCTION__,__LINE__);
if(strlen($line) != 0)
{
$data = unescape($line);
//ECHO (DEBUG_LOG,"TRACE : array poi_id ".$data[0]." /n",__FILE__,__FUNCTION__,__LINE__);
//ECHO (DEBUG_LOG,"TRACE : array expenditure ".$data[4]." /n",__FILE__,__FUNCTION__,__LINE__);
echo mb_convert_encoding($data,"GBK","UTF-8");
}
else
{
//ECHO (WARN_LOG,'WARN : line is null',__FILE__,__FUNCTION__,__LINE__);
}
}
?>