利用discuz的分词服务器实现文章内容自动提取关键字,进而优化网站内链的函数方法方法一:
此方法提取的关键字比较接近
- function getkey($contents){
- //$rows = strip_tags($contents);
- $arr = array(' ',' ',"\s", "\r\n", "\n", "\r", "\t", ">", "“", "”","<br />");
- $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=$qc_rows&ics=gbk&ocs=gbk"));
- preg_match_all("/<kw>(.*)A\[(.*)\]\](.*)><\/kw>/",$data, $out, PREG_SET_ORDER);
- $key="";
- for($i=0;$i<5;$i++){
- $key=$key.$out[$i][2];
- if($out[$i][2])$key=$key.",";
- }
- return $key;
- }
复制代码 |