Skip to content

Instantly share code, notes, and snippets.

@Amegatron
Created October 1, 2020 14:35
Show Gist options
  • Save Amegatron/7d5045352bc6e2513256828d7c98f2f7 to your computer and use it in GitHub Desktop.
Save Amegatron/7d5045352bc6e2513256828d7c98f2f7 to your computer and use it in GitHub Desktop.
Test function for Dostavista
function popularWords($text, $amount = 5)
{
$top = [];
$words = preg_split('~[^[:alnum:]]+~is', strtolower($text), -1, PREG_SPLIT_NO_EMPTY);
foreach ($words as $word) {
if (!isset($top[$word])) {
$top[$word] = 0;
}
$top[$word]++;
}
arsort($top);
return array_slice($top, 0, $amount, true);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment