Hi all I am new in php please helpe to write the script whic take the following string YELLOW MANGOES RED APPLES RED IS MY FAVORITE COLOR MY SHIR IS ALSO RED BUT I DO NOT LIKE YELLOW AND GREEN A COW EATS GREEN GRASS GREEN VISITABLE IS USEFUL FOR HEALTH and through echo statement it should display the word which comes mostly in this script. please help me to do this I will very grateful to you.
I Want to write the script for acceptance for that script and find the word for which comes mostly in it for e.g "RED". then display to it.........
Explode the string by " " then put each word into an array like $array[word][0], if the word is already in the array increment the number after it.
Hi How about this. And by the way "RED" is not the most common word, "RED", "IS", "GREEN" are all equally common <?php $string="YELLOW MANGOES RED APPLES RED IS MY FAVORITE COLOR MY SHIR IS ALSO RED BUT I DO NOT LIKE YELLOW AND GREEN A COW EATS GREEN GRASS GREEN VISITABLE IS USEFUL FOR HEALTH"; $words=explode(" ", $string); $frequency=array_count_values($words); $most=max($frequency); print_r(array_keys($frequency, $most)); ?> Gives Array ( [0] => RED [1] => IS [2] => GREEN ) Kind regards Henry