php 自写函数代码 获取关键字 去超链接
更新时间:2010年02月08日 10:00:49 作者:
根据权重获取关键字 去掉文章中的超链接简单,简洁
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); 这样用正则也可以
复制代码 代码如下:
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中使用jQuery+Ajax实现分页查询多功能操作(示例讲解)
下面小编就为大家带来一篇PHP中使用jQuery+Ajax实现分页查询多功能操作(示例讲解)。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧2017-09-09
如何解决CI框架的Disallowed Key Characters错误提示
本篇文章是对解决CodeIgniter框架应用中,出现Disallowed Key Characters错误提示的方法,进行了详细的分析介绍,需要的朋友可以参考下2013-07-07
phpstorm最新激活码分享亲测phpstorm2021.3版可用
这篇文章主要分享了phpstorm最新激活码亲测phpstorm2021.3.1版可用,如果你的提示过期可以使用phpstorm永久激活补丁+激活码需要的朋友可以参考下2020-11-11
php数组函数序列之array_intersect() 返回两个或多个数组的交集数组
array_intersect() 函数返回两个或多个数组的交集数组。结果数组包含了所有在被比较数组中,也同时出现在所有其他参数数组中的值,键名保留不变。2011-11-11


最新评论