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简单检测404页面的方法示例

php简单检测404页面的方法示例

本文实例讲述了php简单检测404页面的方法。分享给大家供大家参考,具体如下: 需求描述: 检测给定的url是否是404页面。 方式一: 使用file_get_contents函数,可以...

PHP 5.0 Pear安装方法

pear是PHP的扩展和应用程序库,包含了很多有用的类,安装好php5.0后,pear实际上并没有被安装,安装的方法如下:   1.在php目录中双击go-pear....

php定期拉取数据对比方法实例

写在前面 今天在网上看帖子提问的时候,看到有人发表了一个提问 php下载远程的批量文件,每天一次,对比昨天和今天的文件,将旧文件替换成新文件 我们通过这个问题来分析讲解一下其中的知...

PHP笛卡尔积实现算法示例

本文实例讲述了PHP笛卡尔积实现算法。分享给大家供大家参考,具体如下: <?php $arr = array(array(1,3,4,5),array(3,5,7,9)...

php页面跳转代码 输入网址跳转到你定义的页面

代码很简单,涉及到header函数的使用,代码如下 复制代码 代码如下: <?php if (!empty($_SERVER['HTTPS']) && ('on' == $_SER...