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中通过DirectoryIterator删除整个目录的方法

本文实例讲述了php中通过DirectoryIterator删除整个目录的方法。分享给大家供大家参考。具体实现方法如下: <?php function cleanup_...

PHP实现的简单在线计算器功能示例

PHP实现的简单在线计算器功能示例

本文实例讲述了PHP实现的简单在线计算器功能。分享给大家供大家参考,具体如下: <html> <head> <meta http-equiv="cont...

ThinkPHP中自定义目录结构的设置方法

ThinkPHP中自定义目录结构的设置方法

效果如图所示: 入口文件 <?php // 应用入口文件 // 检测PHP环境 if(version_compare(PHP_VERSION,'5.3.0','&...

可兼容php5与php7的cURL文件上传功能实例分析

本文实例讲述了可兼容php5与php7的cURL文件上传功能。分享给大家供大家参考,具体如下: 为啥要写这个示例 最近修改一个项目,需要通过cURL上传文件。 记得之前做过类似实现的,于...

PHP中使用Imagick读取pdf并生成png缩略图实例

pdf生成png首页缩略图 (服务器需要支持Imagick)  复制代码 代码如下:  /** * PDF2PNG    * @...