$val) {
$density = ($val/count($words))*100;
if ($density > 0.5)
echo “$key – COUNT: $val, DENSITY: “.number_format($density,2).”%



//$url = “”;
$str = strip_tags($_POST[text]);

// array_count_values() returns an array using the values of the input array as keys and their frequency in input as values.
// str_word_count($str,1) – returns an array containing all the words found inside the string
$words = str_word_count(strtolower($str),1);

// Calculate the number of words in the text
echo ““.$nb_words = count($words).” Words \n”;

// Array of stop words
$stop_words = array(

// remove the stop word from the array words:
$word_trim = array_diff($words, $stop_words);

// Calculate the number of repetition of words
$word_count = array_count_values($word_trim);

foreach ($word_count as $key => $val) {
$density = ($val/$nb_words)*100;
if ($density > 0.5)
echo “$key – COUNT: $val, DENSITY: “.number_format($density,2).”%


* Ordered by Keyword density