采集百度推荐词、百度下拉框



php
$word
=$_GET['word'];
if ($word=="")
{
echo 
<<<EOF
<form action="" method="get">
  

关键词?: <input type="text" name="word" />p>
  
<input type="submit" value="采集" />
</form>
EOF;
}
else
{

$data=file_get_contents('http:/
/suggestion.baidu.com/su?wd='.$word);
$data=mb_convert_encoding($data, '
UTF-8', 'UTF-8,GBK,GB2312,BIG5' );
$data_temp=strpos($data,"x"); 
$data=substr_replace($data,"",$data_temp,17); 
$data = trim($data,");");
$data = trim($data,"{");
$data=preg_replace("/q:.+?.e,/",'', $data); 
$data = str_replace("[","",$data);
$data = str_replace("]","",$data);
$data = "[".$data."]";
$data = str_replace(",","},s:",$data);
$data = str_replace("s:","{\"s\":",$data);//复杂的处理,以符合json格式
$dc=json_decode($data);
for ($n=0; $n<=9; $n++)
{
$wd[$n]=$dc[$n]->s;
echo "
".$wd[$n];
}

}
?>

转载请说明出处 http://d260288701.blog.163.com/blog/


你可能感兴趣的:(PHP)