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

yipeiwu_com6年前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("/<kw>(.*)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 .*?>(.*?)<\/a>/i","\${1}", $content); 这样用正则也可以

相关文章

PHP中substr()与explode()函数用法分析

本文实例讲述了PHP中substr()与explode()函数用法。分享给大家供大家参考。具体方法如下: substr(string,start,length):本函数将字符串 stri...

PHP @ at 记号的作用示例介绍

看PHP的代码,总有些行前边有@符号,一直不知道是什么意思。 例如dede5.7 @ni=imagecreatetruecolor(ftoW,$ftoH); 今天用到了,就记一下吧。其实...

php定期拉取数据对比方法实例

写在前面 今天在网上看帖子提问的时候,看到有人发表了一个提问 php下载远程的批量文件,每天一次,对比昨天和今天的文件,将旧文件替换成新文件 我们通过这个问题来分析讲解一下其中的知...

php实现word转html的方法

本文实例讲述了php实现word转html的方法。分享给大家供大家参考,具体如下: 要想完美解决,office转pdf或者html,最好还是用windows office软件,libre...

PHP 使用Echarts生成数据统计报表的实现代码

PHP 使用Echarts生成数据统计报表的实现代码

echarts统计,简单示例 先看下效果图 看下代码 HTML页面 为ECharts准备一个Dom,宽高自定义 <div class="panel panel-info"&g...