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?? 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); ?> Link to comment https://forums.phpfreaks.com/topic/148857-array/#findComment-781665 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.