note 55829 added to function.str-word-count
| From: | jteyatuoguelphdotca at osu1 dot php dot net | Date: | Sun, 14 Aug 2005 23:21:35 +0000 |
| Subject: | note 55829 added to function.str-word-count | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-93652@lists.php.net to get a copy of this message | ||
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.
----
Manual Page -- http://www.php.net/manual/en/function.str-word-count.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+55829
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+55829&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+55829&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+55829&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+55829&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+55829&report=yes&reason=non-english
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+55829&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+55829&report=yes
Search -- http://master.php.net/manage/user-notes.php