微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

php 自写函数代码 获取关键字 去超链接

1.根据权重获取关键字


代码如下:
function getkey($contents){
$rows = strip_tags($contents);
$arr = array(' ','',"\s","\r\n","\n","\r","\t",">","“","”");
$qc_rows = str_replace($arr,$rows);
if(strlen($qc_rows)>2400){
$qc_rows = substr($qc_rows,'0','2400');
}
$data = @implode('',file("http://keyword.discuz.com/related_kw.html?title=$contents&ics=gbk&ocs=gbk"));
preg_match_all("/(.*)A\[(.*)\]\](.*)><\/kw>/",$data,$out,PREG_SET_ORDER);
for($i=0;$i<5;$i++){
$key=$key.$out[$i][2];
if($out[$i][2])$key=$key.",";
}
return $key;
}
//$contents为你要得到关键字的文章

2.去掉文章中的超链接简单,简洁

代码如下:
function get_new_content($content){
include("../simple_html_dom.PHP");
$html = str_get_html($content);
$a_href = $html->find('a');
foreach($a_href as $link){
$text = $link->plaintext;//链接中的文字;
$link->outertext = $text;
}
$Now_content = $html->save();
}
//preg_replace("/(.*?)<\/a>/i","\${1}",$content); 这样用正则也可以

原文地址:https://www.jb51.cc/php/28800.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐