note 103456 added to function.str-word-count
| From: | ZulfugarIsmayilzadehadmin at mid dot az | Date: | Thu, 14 Apr 2011 11:52:06 +0000 |
| Subject: | note 103456 added to function.str-word-count | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-178823@lists.php.net to get a copy of this message | ||
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);
?>
----
Server IP: 69.147.83.197
Probable Submitter: 46.18.65.26
----
Manual Page -- http://www.php.net/manual/en/function.str-word-count.php
Edit -- https://master.php.net/note/edit/103456
Del: integrated -- https://master.php.net/note/delete/103456/integrated
Del: useless -- https://master.php.net/note/delete/103456/useless
Del: bad code -- https://master.php.net/note/delete/103456/bad+code
Del: spam -- https://master.php.net/note/delete/103456/spam
Del: non-english -- https://master.php.net/note/delete/103456/non-english
Del: in docs -- https://master.php.net/note/delete/103456/in+docs
Del: other reasons-- https://master.php.net/note/delete/103456
Reject -- https://master.php.net/note/reject/103456
Search -- https://master.php.net/manage/user-notes.php