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)文章
mayfish 數(shù)據(jù)入庫驗(yàn)證代碼
mayfish 可以靈活的自定義將要執(zhí)行寫入的數(shù)據(jù)內(nèi)容的校驗(yàn)規(guī)則,以減少開發(fā)人員手動對每一個字段的數(shù)據(jù)進(jìn)行校驗(yàn)的麻煩。2010-04-04PHP strip_tags保留多個HTML標(biāo)簽的方法
這篇文章主要介紹了PHP strip_tags保留多個HTML標(biāo)簽的方法,需要的朋友可以參考下2016-05-05php實(shí)現(xiàn)QQ空間獲取當(dāng)前用戶的用戶名并生成圖片
這篇文章主要介紹了php實(shí)現(xiàn)QQ空間獲取當(dāng)前用戶的用戶名并生成圖片的方法,涉及php針對QQ空間及接口調(diào)用的相關(guān)技巧,具有一定參考借鑒價值,需要的朋友可以參考下2015-07-07深入理解PHP中mt_rand()隨機(jī)數(shù)的安全
mt_rand()使用mersennetwister算法返回隨機(jī)整數(shù),這個大家都知道,但下面這篇文章主要給大家介紹的是關(guān)于PHP中mt_rand()隨機(jī)數(shù)安全的相關(guān)資料,文中介紹的非常詳細(xì),需要的朋友可以參考借鑒,下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧。2017-10-10Windows下的PHP安裝文件線程安全和非線程安全的區(qū)別
Windows版的PHP從版本5.2.1開始有Thread Safe。這兩者不同在于何處?到底應(yīng)該用哪種?這里做一個簡單的介紹2014-04-04