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); 这样用正则也可以

相关文章

基于pear auth实现登录验证

建立一个名为yz.php的页面 复制代码 代码如下: <?php require_once('Auth.php'); function show_login_form () { e...

什么是PHP7中的孤儿进程与僵尸进程

基本概念 我们知道在unix/linux中,正常情况下,子进程是通过父进程创建的,子进程在创建新的进程。子进程的结束和父进程的运行是一个异步过程,即父进程永远无法预测子进程 到底什么时...

详解WordPress中添加和执行动作的函数使用方法

add_action()(添加动作) add_action() 函数用来挂载一个函数到动作钩子上。 用法 add_action( $tag, $function_to_add, $p...

apache配置虚拟主机的方法详解

1.apache配置文件中打开vhost的配置LoadModule vhost_alias_module modules/mod_vhost_alias.soInclude conf/e...

PHP学习的技巧和学习的要素总结

1、适合PHP学习者的学习道路: (1) 了解HTML/CSS/JS、、网页根本元素,完毕阶段可自行制造简略的网页,对元素特点相对了解 (2) 了解动态言语的概念和运做机制,了解根本的P...