您现在的位置是:芭奇站群管理系统 > 学习收录 > -> 根据标题获得百度热门相关关键字的SEO函数

根据标题获得百度热门相关关键字的SEO函数

时间:2014-09-23 12:50

根据标题获得百度热门相关关键字的SEO函数
function baiduKeyword($title,$num=5,$charset="UTF-8"){

$title=iconv($charset, “GB2312″, $title);
$w=file_get_contents(‘http://d.baidu.com/rs.php?q=’.urlencode($title).’&tn=baidu’);
//die($w);
//获得列表部分
preg_match_all(“|

(.*)
|isU”,$w,$con);
$list=$con[1][0];
//获得具体内容
preg_match_all(“|

(.*)
(.*)

|isU”,$list,$content);
//合并成数组,被搜索次数做为键值
$c=array_combine($content[4],$content[3]);
//排序
krsort($c);
//取前N条
$r=array_slice($c, 0, $num);
//转换成字符串
$result=implode(“,”, $r);
$result=iconv(“GB2312″, $charset,$result);
return $result;
}

//通过DZ获取文章关键字,输入标题和内容 即可返回5个关键字数组
function getTags($title,$content){

$subjectenc = rawurlencode(strip_tags($title));
$messageenc = rawurlencode(strip_tags(preg_replace(“/\[.+?\]/U”, ”,$content)));
$subjectenc =substr($subjectenc,0,60);
$messageenc=substr($messageenc,0,1200);
$data = @implode(”, file(“http://keyword.discuz.com/related_kw.html?title=$subjectenc&content=$messageenc&ics=utf-8&ocs=utf-8″));

$kws = array();
if($data) {
$parser = xml_parser_create();
xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
xml_parse_into_struct($parser, $data, $values, $index);
xml_parser_free($parser);
foreach($values as $valuearray) {
if($valuearray['tag'] == ‘kw’ || $valuearray['tag'] == ‘ekw’) {
$kw =trim($valuearray['value']);
$kws[] =$kw ;

}
}
}
return $kws;
}

echo baiduKeyword(“ajax”,20,”GB2312″);

?>