? $file = fopen("D:/download/tran/wordsrc.txt","r");
$text=fread($file,filesize("D:/download/tran/wordsrc.txt"));
fclose($file);
$of = fopen('D:/download/tran/translate.txt','a');//创建并打开dir.txt
$sv=1;
$voc=1;
$
word="";
$err=1;
$errcnt=0;
if(!empty($text))
{
$word=preg_split('/[\r\n\t,]+/', $text);
foreach($word as $value)
{
$err=1;
echo "\rProceeding:$value\t\t\t\t";
if(empty($value)) continue;
$ech=uc_fopen("dict-co.iciba/api/dictionary.php?w=".$value);
$pon=xmlarray($ech,"dict");//取出各个节点
$result="";//预清除变量
if(sizeof($pon)>1)
foreach($pon as $detail)
$result=$result.$detail."\n";//将单词翻译结果链接
$result=DelEtrWh($result);
$result=$result."\n";
if($of)
fwrite($of,preg_replace("/\[\d{2}:\d{2}\.\d{2}\]/","",$result));//把执行文件的结果写入txt文件
if(!$err)
CrLrc($result,$value);//生成lrc
}
fclose($of);
}
else
echo "empty src";
?>
//将stream保存为filename.lrc
function CrLrc($stream,$filename)
{
$lrc = fopen('D:/download/tran/lrc/'.$filename.'.lrc','w');
fwrite($lrc,$stream);
fclose($lrc);
}
function DelEtrWh($str){
$str = trim($str);
$str = ereg_replace("\t+","\t",$str);
$str = ereg_replace("(\r\n)+","\r\n",$str);
$str = ereg_replace("(\n)+","\n",$str);
$str = ereg_replace("(\r)+","\r",$str);
return trim($str);
}
/* 将$path的二重xml提取为数组 */
function xmlarray($string,$top)
{
Global $voc;
Global $err;
Global $errcnt;
if(empty($string))
{
if(($errcnt++)<10)
return "\nemty stream\n";
else
die("the net is off'!\n");
}
$errcnt=0;
$array=array();
$
xml =new SimpleXMLElement($string);
if(!empty($xml))
{
foreach($xml->children() as $child)
{
$i++;
if(!preg_match("/http:\/\/.+?\.mp3/",$child))
{
$time+=50;
$mm=$time%100;
$scd=(int)($time-$mm)/100;
$min=(int)($time-$scd*100-$mm)/6000;
$stamp="[".bit2($min).":".bit2($scd).".".bit2($mm)."]";
if($i==1){
$keyw=$child;//该单词
array_push($array,$stamp.">::>".$child);
}
else
array_push($array,$stamp.$child);
}
elseif($voc)//语音保存
{
$err=0;
$str="D:/download/tran/mp3/".$keyw.".mp3";
//if(!($first++))//只保存第一个发音
//file_put_contents($str,file_get_contents($child));
}
}
}
return $array;
}
function bit2($x)
{
if($x<10)
return "0$x";
else return "$x";
}
function get_ip(){
if (getenv("HTTP_CLIENT_IP") &;&; strcasecmp(getenv("HTTP_CLIENT_IP"), "unknown"))
$ip = getenv("HTTP_CLIENT_IP");
else if (getenv("HTTP_X_FORWARDED_FOR") &;&; strcasecmp(getenv("HTTP_X_FORWARDED_FOR"), "unknown"))
$ip = getenv("HTTP_X_FORWARDED_FOR");
else if (getenv("REMOTE_ADDR") &;&; strcasecmp(getenv("REMOTE_ADDR"), "unknown"))
$ip = getenv("REMOTE_ADDR");
else if (isset($_SERVER['REMOT
E_ADDR']) &;&; $_SERVER['REMOTE_ADDR'] &;&; strcasecmp($_SERVER['REMOTE_ADDR'], "unknown"))
$ip = $_SERVER['REMOTE_ADDR'];
else
$ip = "unknown";
return($ip);
}
function uc_fopen($url, $limit = 0, $post = '', $cookie = '', $bysocket = FALSE, $ip = '', $timeout = 1, $block = TRUE) {
$return = '';
$matches = parse_url($url);
!isset($matches['host']) &;&; $matches['host'] = '';
!isset($matches['path']) &;&; $matches[