chomedey Posted February 24, 2010 Share Posted February 24, 2010 I'm using this function to return a word count on a user-submitted entry: function adv_count_words($str){ // used to count words for stats $words = 0; $str = eregi_replace(" +", " ", $str); $array = explode(" ", $str); for($i=0;$i < count($array);$i++) { if (eregi("[0-9A-Za-zÀ-ÖØ-öø-ÿ]", $array[$i])) $words++; } return $words; } The only problem is that when I write one word, followed by a carriage return, and then another word, followed by a carriage return, etc., the function returns a value of one. Does anyone know how to fix this? I also hear that eregi is a deprecated function. Does anyone know what I should be using instead? Thanks. Julian Link to comment https://forums.phpfreaks.com/topic/193212-word-count-function-improvement/ Share on other sites More sharing options...
jl5501 Posted February 24, 2010 Share Posted February 24, 2010 Is there any reason you are not using str_word_count() ? Link to comment https://forums.phpfreaks.com/topic/193212-word-count-function-improvement/#findComment-1017420 Share on other sites More sharing options...
chomedey Posted February 24, 2010 Author Share Posted February 24, 2010 Would that work? Link to comment https://forums.phpfreaks.com/topic/193212-word-count-function-improvement/#findComment-1017437 Share on other sites More sharing options...
chomedey Posted February 24, 2010 Author Share Posted February 24, 2010 I'm an idiot - forgive me. Link to comment https://forums.phpfreaks.com/topic/193212-word-count-function-improvement/#findComment-1017441 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.