復制代碼 代碼如下:
function escape($str){
preg_match_all('/[/x80-/xff].|[/x01-/x7f]+/',$str,$r);
$ar = $r[0];
foreach($ar as $k=>$v){
if(ord($v[0]) < 128)
$ar[$k] = rawurlencode($v);
else
$ar[$k] = '%u'.bin2hex(iconv('GB2312','UCS-2',$v));
}
return join('',$ar);
}
復制代碼 代碼如下:
function chacy($chengyu){
$chengyu=escape($chengyu);
$text=@file_get_contents('http://study.hongen.com/dict/ndsearchchengyu.aspx?type=exact&word='.$chengyu);
$pos1=strpos($text,'<table>');
$pos2=strrpos($text,'<table>');
$text=substr($text,$pos1,$pos2-$pos1);
//把字符集由原來的UTF-8轉換到GB2312,注意在GB2312之后加上了//IGNORE,強制遇到特殊字符也繼續轉換,因為在遇到漢字“一”的時候iconv函數會終止轉換
$text=iconv('UTF-8','GB2312//IGNORE',$text);
if (strpos($text,'出處')){
return $text;
}
}
新聞熱點
疑難解答