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验证码 附调用方法

既简单又安全的PHP验证码 附调用方法

一、验证码示例 二、php验证码类,secoder.class.php <?php /** * 安全验证码 * * 安全的验证码要:验证码文字扭曲、旋...

php写app用的框架整理

PHP开发app常用的三种框架介绍 1、ThinkPHP框架 TP框架是一共快速兼容简单的轻量级国产PHP开发框架,使用面向对象的结构和MVC模式进行开发。它可以支持Windows、Li...

php采用ajax数据提交post与post常见方法总结

本文实例讲述了php采用ajax数据提交post与post常见方法。分享给大家供大家参考。具体方法如下: 在很多情况下我们使用ajax是不会有什么问题的,但有时会碰到ajax数据提交po...

PHP 函数语法介绍一

复制代码 代码如下:function getAdder($x) { return function ($y) use ($x) { return $x + $y; }; } $adder...

解析PHP计算页面执行时间的实现代码

如下所示:复制代码 代码如下:<?php  $t = new executeTime;  phpinfo();  class executeTime{...