Такой примерчик:
в формочку вставляем текст, и получаем отсортированый масив
function is_relevant($var) {
if ( (!empty($var) && (strlen($var)>4) ) ) return 1;
else return 0;
}
function lowercase_cyr($source_text)
{
return strtr($source_text,\'АБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЬЫЪЭЮЯЇІЄ\',\'абвгдеёжзийклмнопрстуфхцчшщьыъэюяїіє\');
}
if (!empty($target)) {
$dest="http://127.0.0.1/".$target;
$fp = @fopen ($dest, \'r\');
if ($fp) {
while (! feof ($fp)) {$content .= fgets ($fp, 4096);}
fclose($fp);
}
$words=preg_split("\'\\s+\'i"," {$content} ");
sort($words);
$relevant=array();
$rel=array();
for ($i=1;$i if (is_relevant($words[$i])) {
$word=$words[$i];
$word=strtr($words[$i],"“”«».!«,?"," ");
$word = eregi_replace ("[[:digit:][:punct:][:space:][:alpha:]]","",$word);
$word=substr($word, 0,-1);
$word=lowercase_cyr($word);
if (is_relevant($word)) $rel[] =$word;
}
}
$relevant = array_count_values($rel);
arsort($relevant);
}
echo "
";
echo "
\\n";
print_r($relevant);
echo "\\n
\\n";
?>
A вот например tak:
$text = \'Searches subject for all matches to the regular expression given in pattern and puts them in matches in the order specified by order.
After the first match is found, the subsequent searches are continued on from end of the last match.
order can be one of two things:\';
$search_words = array (\'match\', \'search\', \'order\', \'the\');
$result = array();
foreach ($search_words as $word)
{
preg_match_all (\'/(?im)\'.$word.\'/\', $text, $matches);
$result[$word] = sizeof ($matches[0]);
}
echo \'\';
print_r ($result);
echo \'
\';