发新话题
打印

SEO的几个函数,分词,优化

SEO的几个函数,分词,优化

[Copy to clipboard]
PHP CODE:
//根据标题获得百度热门相关关键字,返回字符串
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("|[list][*](.*)[*][url=http://www.dophp.net/(.*)](.*)[/url][*][img]http://img.baidu.com/img/bar_1.gif[/img][/list]|isU",$list,$content);
//合并成数组,被搜索次数做为键值
$c=array_combine($content[4],$content[3]);
//排序
krsort($c);
//取前N条
$r=array_slice($c0$num); 
//转换成字符串
$result=implode(","$r);
$result=iconv("GB2312"$charset,$result);
return 
$result;
}


[Copy to clipboard]
PHP CODE:
//通过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($parserXML_OPTION_CASE_FOLDING0);
                
xml_parser_set_option($parserXML_OPTION_SKIP_WHITE1);
                
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;
}


交流QQ群2:16142493
智能手机软件下载
PHP新手不可错过一帖
PHP新手如何获得积分
论坛需要你,我们大家需要你!

TOP

牛啊,竟然研究SEO了???

TOP

支持seo~~~~~~~~~

TOP

学习了……

TOP

发新话题