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 number_format() 函数通过千位分组来格式化数字的实现代码

定义和用法number_format() 函数通过千位分组来格式化数字。 语法number_format(number,decimals,decimalpoint,separator)...

thinkphp中U方法按路由规则生成url的方法

如下所示: //更改模块配置文件 'URL_ROUTER_ON' => true, 'URL_ROUTE_RULES'=>[]//编写路由优化 tp开启路由后,使...

php使用数组填充下拉列表框的方法

本文实例讲述了php使用数组填充下拉列表框的方法。分享给大家供大家参考。具体实现方法如下: <?php $data = array( (object)array("...

sourcesafe管理phpproj文件的补充说明(downmoon)

sourcesafe管理phpproj文件的补充说明(downmoon)

后来发现sourcesafe管理界面,(Admin登录),tools——Options——File Types——File Group——Add "PHP"——“*.php;*.phpp...

PHP设计模式之适配器模式定义与用法详解

本文实例讲述了PHP设计模式之适配器模式定义与用法。分享给大家供大家参考,具体如下: 适配器很容易理解, 大多数人家庭都有手机转接器, 用来为移动电话充电,这就是一种适配器. 如果只有U...