Home > Backend Development > PHP Tutorial > php中自动提取文章内容关键字seo优化网站的函数步骤

php中自动提取文章内容关键字seo优化网站的函数步骤

WBOY
Release: 2016-06-13 13:13:32
Original
1364 people have browsed it

php中自动提取文章内容关键字seo优化网站的函数方法

利用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; 
}
Copy after login
?


方法二:此方法提取的关键字相对上面差一点点

function getkey($contents){ 
	$key = '';
	$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; 
}
Copy after login
?
海口?http://www.souhaikou.com

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template