common Posted March 10, 2009 Share Posted March 10, 2009 Hi everyone Ive got a textarea on one page, and on the next page i change it to an array. I want to count each word that occurs in the text, but i dont now what text would be. Can anyone help me, i thought of using an in_array?? Quote Link to comment https://forums.phpfreaks.com/topic/148857-array/ Share on other sites More sharing options...
premiso Posted March 10, 2009 Share Posted March 10, 2009 I think the best approach would be to use str_word_count Then when you get the array of words, loop through them with foreach <?php $string = "This is a string of words in a string sting of the next string to be a string"; $words = str_word_count($string, 1); foreach ($words as $word) { $countArray[$word]++; } print_r($countArray); ?> Quote Link to comment https://forums.phpfreaks.com/topic/148857-array/#findComment-781665 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.