note 103456 deleted from function.str-word-count by danbrown
| From: | danbrown@php.net | Date: | Fri, 31 Aug 2012 16:24:26 +0000 |
| Subject: | note 103456 deleted from function.str-word-count by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-190358@lists.php.net to get a copy of this message | ||
Note Submitter: Zulfugar Ismayilzadeh admin at mid dot az
----
This function count words. But this function works with UTF-8 too.
<?php
/**
* @author Zulfugar Ismayilzadeh
* @copyright 2011
*/
function count_words($string){
$string = trim(preg_replace("/\s+/"," ",$string));
$word_array = explode(" ", $string);
$num = count($word_array);
return $num;
}
$str = "Hello fri3nd, you're looking good today!";
echo count_words($str);
?>