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

yipeiwu_com5年前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实现的登录页面信息提示功能示例

本文实例讲述了PHP实现的登录页面信息提示功能。分享给大家供大家参考,具体如下: login.php: <!DOCTYPE html> <html> <...

php支持中文字符串分割的函数

str_split不支持中文,利用mb_xx函数实现个 /** * Convert a string to an array * @param string $str * @p...

PHP合并数组+号和array_merge的区别

PHP的数组融合一般有两种做法,一种是直接使用加号相加,另一种则是使用array_merge函数进行相加,两者之间有点区别: 1.相加会证数组中的自然index不被重置 2.相加方法中,...

php 重写分页器 CLinkPager的实例

php 重写分页器 CLinkPager的实例 1、自定义的分页器类放在哪里? 有两个位置可以放, 第一种是放在 protected/extensions 中,在使用是import...

php中时间轴开发(刚刚、5分钟前、昨天10:23等)

其实这个没什么技术含量,当然就直接贴代码,不废话了, 但是在其实开发中还是蛮有用的,譬如论坛帖子,围脖等都有相关应用 复制代码 代码如下: function tranTime($time...