onlyican Posted February 19, 2007 Share Posted February 19, 2007 Hey people I need to check the amount of "Words" in a string, and I forgot how to do it I know strlen counts the number of chars in a string, I want the amount of words I think there is a function out there but I cant remember. Link to comment https://forums.phpfreaks.com/topic/39160-number-of-words/ Share on other sites More sharing options...
snakebit Posted February 19, 2007 Share Posted February 19, 2007 I don't how good it's but you can tray it : preg_match_all("\b[a-zA-Z]+\b", $text, $matches); echo count($matches[0]); Link to comment https://forums.phpfreaks.com/topic/39160-number-of-words/#findComment-188577 Share on other sites More sharing options...
onlyican Posted February 19, 2007 Author Share Posted February 19, 2007 I could also do something like <?php function CountWords($Str){ $words = explode(" ", $str); $NumWords = count($words); return $NumWords; } ?> But I thought there was already a function out there Link to comment https://forums.phpfreaks.com/topic/39160-number-of-words/#findComment-188588 Share on other sites More sharing options...
mihail Posted February 19, 2007 Share Posted February 19, 2007 str_word_count($string) Link to comment https://forums.phpfreaks.com/topic/39160-number-of-words/#findComment-188594 Share on other sites More sharing options...
onlyican Posted February 19, 2007 Author Share Posted February 19, 2007 thank you, as I said, i thought there was a function in php Link to comment https://forums.phpfreaks.com/topic/39160-number-of-words/#findComment-188612 Share on other sites More sharing options...
itsmeArry Posted March 1, 2007 Share Posted March 1, 2007 str_word_count($string) is a php function Link to comment https://forums.phpfreaks.com/topic/39160-number-of-words/#findComment-197013 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.