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中动态变量用法。分享给大家供大家参考。具体分析如下: 定义的固定变量: $my_pic_1=$row["pic_1"]; $my_pic_2=$row["pic_...

深入密码加salt原理的分析

我们知道,如果直接对密码进行散列,那么黑客可以对通过获得这个密码散列值,然后通过查散列值字典(例如MD5密码破解网站),得到某用户的密码。加Salt可以一定程度上解决这一问题。所谓加Sa...

PHP循环获取GET和POST值的代码

复制代码 代码如下:if(is_array($HTTP_GET_VARS))     {     &nbs...

PHP实现定时执行任务的方法

本文实例讲述了PHP实现定时执行任务的方法,代码简单实用。分享给大家供大家参考。 具体实现方法如下: ignore_user_abort(true); //客户端断开时忽略脚本中止(...

php获取文章内容第一张图片的方法示例

本文实例讲述了php获取文章内容第一张图片的方法。分享给大家供大家参考,具体如下: <?php $temp=mt_rand(1,4); $pattern="/<[...