core/api/php/kwg.php

44 lines
1.8 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?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);
}
?>