PHP custom function code to get keywords to hyperlink
- 2020-03-31 20:20:47
- OfStack
1. Get keywords according to the weight
2. Remove hyperlinks from articles simply and succinctly
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("/<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 is the article where you want to get the keyword
2. Remove hyperlinks from articles simply and succinctly
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;//Text in links;
$link->outertext = $text;
}
$now_content = $html->save();
}
//The preg_replace (" / <A. *?> (. *?) < / a> / I ", "${1}", $content); You can also use regularization in this way