Home > Backend Development > PHP Tutorial > PHP self-written function code to obtain keywords and remove hyperlinks_PHP tutorial

PHP self-written function code to obtain keywords and remove hyperlinks_PHP tutorial

WBOY
Release: 2016-07-21 15:41:48
Original
1072 people have browsed it

1. Get keywords based on weight

Copy code The code is as follows:

function getkey ($contents){
$rows = strip_tags($contents);
$arr = array(' ',' ',"s", "rn", "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("/(.*)A[(.*)]](.*)>/", $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 is the keyword you want to get Article


2. Removing hyperlinks in the article is simple and concise

Copy code The code is as follows:

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;//The text in the link;
$link->outertext = $text;
}
$now_content = $html->save();
}
//preg_replace("/(.*?)/i","${1}", $content); You can also use regular expressions in this way

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/321115.htmlTechArticle1. Get keywords based on weight. Copy the code. The code is as follows: function getkey($contents){ $rows = strip_tags( $contents); $arr = array(' ','',"s", "rn", "n", "r", "t", "", "", "");...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template