note 55829 deleted from function.str-word-count by danbrown

From: Date: Fri, 31 Aug 2012 16:28:36 +0000
Subject: note 55829 deleted from function.str-word-count by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-190375@lists.php.net to get a copy of this message
Note Submitter: jtey at uoguelph dot ca ---- In the previous note, the example will only extract from the string, words separated by exactly one space. To properly extract words from all strings, use regular expressions. Example (extracting the first 4 words): <?php $string = "One two three four five six"; echo implode(" ", array_slice(preg_split("/\s+/", $string), 0, 4)); ?> The above $string would not have otherwise worked when using the explode() method below.

« previous php.notes (#190375) next »