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. Quote 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]); Quote 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 Quote 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) Quote 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 Quote 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 Quote Link to comment https://forums.phpfreaks.com/topic/39160-number-of-words/#findComment-197013 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.