core/api/php/kwg.php

44 lines
1.8 KiB
PHP
Raw Normal View History

2022-12-11 13:55:49 +05:00
<?php
function seokeywords($contents,$symbol=5,$words=70){
$contents = @preg_replace(array("'<[\/\!]*?[^<>]*?>'si","'([\r\n])[\s]+'si","'&[a-z0-9]{1,6};'si","'( +)'si"),
array("","\\1 "," "," "),strip_tags($contents));
$rearray = array("~","!","@","#","$","%","^","&","*","(",")","_","+",
"`",'"',"",";",":","?","-","=","|","\"","\\","/",
"[","]","{","}","'",",",".","<",">","\r\n","\n","\t","«","»");
$adjectivearray = array("ые","ое","ие","ий","ая","ый","ой","ми","ых","ее","ую","их","ым",
"как","для","что","или","это","этих",
"всех","вас","они","оно","еще","когда",
"где","эта","лишь","уже","вам","нет",
"если","надо","все","так","его","чем",
"при","даже","мне","есть","только","очень",
"сейчас","точно","обычно"
);
$contents = @str_replace($rearray," ",$contents);
$keywordcache = @explode(" ",$contents);
$rearray = array();
foreach($keywordcache as $word){
if(strlen($word)>=$symbol && !is_numeric($word)){
$adjective = substr($word,-2);
if(!in_array($adjective,$adjectivearray) && !in_array($word,$adjectivearray)){
$rearray[$word] = (array_key_exists($word,$rearray)) ? ($rearray[$word] + 1) : 1;
}
}
}
@arsort($rearray);
$keywordcache = @array_slice($rearray,0,$words);
$keywords = "";
foreach($keywordcache as $word=>$count){
$keywords.= ",".$word;
}
return substr($keywords,1);
}
?>