php: sort and count instances of words in a given string
Posted
by superUntitled
on Stack Overflow
See other posts from Stack Overflow
or by superUntitled
Published on 2010-06-06T15:40:58Z
Indexed on
2010/06/06
15:42 UTC
Read the original article
Hit count: 302
php
Hello, I need help sorting and counting instances of the words in a string.
Lets say I have a collection on words:
happy beautiful happy lines pear gin happy lines rock happy lines pear
How could I use php to count each instance of every word in the string and output it in a loop:
There are $count instances of $word
So that the above loop would output:
There are 4 instances of happy. There are 3 instances of lines. There are 2 instances of gin....
Thank you for your genius.
© Stack Overflow or respective owner