复制代码 代码如下:
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;
}
}
新闻热点
疑难解答