程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 網頁編程 >> PHP編程 >> 關於PHP編程 >> php 自寫函數代碼 獲取關鍵字 去超鏈接

php 自寫函數代碼 獲取關鍵字 去超鏈接

編輯:關於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); 這樣用正則也可以

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved