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压缩HTML函数轻松实现压缩html/js/Css及注意事项

压缩HTML的起因 如何提高网页加载速度 ,需要怎么对html页面优化相信是每个拟提高建站技术站长曾想到的问题,其实网页优化的方法还是很多。 有童鞋询问higrid如何 压缩HTML,也...

方便实用的PHP生成静态页面类(非smarty)第1/2页

复制代码 代码如下:/*********************/ /* */ /* Version : 5.2.5 */ /* Author : liqiangwork#sohu.co...

PHP mail()函数使用及配置方法

配置 工欲善其事,必先利其器。首先我们以windows下面为例进行说明,如何配置一下本地的mail。 下载附件 sendmail.zip -解压到任意路径,修改sendmail...

MacOS 安装 PHP的图片裁剪扩展Tclip

Tclip 用于图片裁剪,有以下特点: 能进行人脸识别。图片中有人脸,将自动视为人脸区域为重要区域,将不会被裁剪掉。 自动识别其它重要区域。如果图片中未识别出人脸,则会根据特征分布计算出...

php开发环境配置记录

【apache安装】 复制代码 代码如下: httpd.exe -k install -n "apache2.2.15" httpd.exe -k start -n "apache2.2...