php 自寫函數(shù)代碼 獲取關(guān)鍵字 去超鏈接
更新時間:2010年02月08日 10:00:49 作者:
根據(jù)權(quán)重獲取關(guān)鍵字 去掉文章中的超鏈接簡單,簡潔
1.根據(jù)權(quán)重獲取關(guān)鍵字
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為你要得到關(guān)鍵字的文章
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); 這樣用正則也可以
復(fù)制代碼 代碼如下:
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為你要得到關(guān)鍵字的文章
2.去掉文章中的超鏈接簡單,簡潔
復(fù)制代碼 代碼如下:
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); 這樣用正則也可以
相關(guān)文章
php實現(xiàn)QQ空間獲取當前用戶的用戶名并生成圖片
這篇文章主要介紹了php實現(xiàn)QQ空間獲取當前用戶的用戶名并生成圖片的方法,涉及php針對QQ空間及接口調(diào)用的相關(guān)技巧,具有一定參考借鑒價值,需要的朋友可以參考下2015-07-07Windows下的PHP安裝文件線程安全和非線程安全的區(qū)別
Windows版的PHP從版本5.2.1開始有Thread Safe。這兩者不同在于何處?到底應(yīng)該用哪種?這里做一個簡單的介紹2014-04-04