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实现自动识别Restful API的返回内容类型

如题,PHP如何自动识别第三方Restful API的内容,自动渲染成 json、xml、html、serialize、csv、php等数据? 其实这也不难,因为Rest API也是基于...

PHP扩展Swoole实现实时异步任务队列示例

本文实例讲述了PHP扩展Swoole实现实时异步任务队列。分享给大家供大家参考,具体如下: 假如要发100封邮件,for循环100遍,用户直接揭竿而起,什么破网站! 但实际上,我们很可能...

浅谈PHP 闭包特性在实际应用中的问题

呃,其实大部分情况下是可以的,而有些方面还是令人非常的困扰,下面慢慢道来。 很多语言的都提供了非常优雅和漂亮的操作数组的方法。在下面的例子中,会使用 PHP5.3 以及其他语言提供的闭包...

strpos() 函数判断字符串中是否包含某字符串的方法

用php的strpos() 函数判断字符串中是否包含某字符串的方法 判断某字符串中是否包含某字符串的方法 if(strpos('www.idc-gz.com','idc-gz') !...

php-perl哈希算法实现(times33哈希算法)

复制代码 代码如下:APR_DECLARE_NONSTD(unsigned int) apr_hashfunc_default(const char *char_key, &n...