class Additional_Text_Tegs
{
function getTegs($content, $title, $count = 3, $simplyWords = null)
{
$original = array();
$sources = array();
$titles = array();
$use_simply = (is_array($simplyWords) && count($simplyWords));
$title = preg_replace("/<.*>|\&\#\d+;/iUs", " ", $title);
$title_list = preg_split("/[^\w\d\.]+/", $title);
foreach ($title_list as &$value)
{
while (substr($value, -1) == '.' && strlen($value)) $value = substr($value, 0, -1);
$value = strtolower($value);
$original[strtolower($value)] = $value;
}
$content = preg_replace("/<.*>|\&\#\d+;/iUs", " ", $content);
$content_list = preg_split("/[^\w\d\.]+/", $content);
foreach ($content_list as &$value)
{
while (substr($value, -1) == '.' && strlen($value)) $value = substr($value, 0, -1);
$original[strtolower($value)] = $value;
}
foreach ($content_list as $value)
{
$low = strtolower($value);
if (substr($low, -1) == 's' && key_exists(substr($low, 0, -1), $original)) $low = substr($low, 0, -1);
if (
(strlen($value) > 3) &&
(!$use_simply || !in_array($low, $simplyWords) )
)
{
if (in_array($low, $title_list)) @$titles[$low]++; else @$sources[$low]++;
}
}
unset($content_list);
unset($title_list);
//echo $content;
$i = 0;
$tegs = array();
arsort($titles);
//print_r($titles);
if (count($titles))
{
foreach ($titles as $teg => $popular)
{
$tegs[$i++] = (isset($original[$teg]) ? $original[$teg] : $teg);
if ($i >= $count) break;
}
}
if ($i < $count && count($sources))
{
arsort($sources);
//print_r($sources);
foreach ($sources as $teg => $popular)
{
if ( ($popular == 1 && count($tegs)) || $i >= $count) break;
$tegs[$i++] = (isset($original[$teg]) ? $original[$teg] : $teg);
}
}
//print_r($tegs);
//exit;
return $tegs;
}
}