note 51681 added to function.strtok
| From: | cs2xz at bath dot ac dot uk | Date: | Thu, 07 Apr 2005 13:30:17 +0000 |
| Subject: | note 51681 added to function.strtok | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-87650@lists.php.net to get a copy of this message | ||
There is a method to remove all the punctuations and only put the words into an array called
"$token", where variable $invalid lists all the punctuations and "\xxx" are the
octal numbers of punctuations. At the end, dispalys total number of words in $string and the 4th
words in the string.
$string = "Hello, $%^\n\\\"jeff!!!!\"/. 'How are you!'";
$invalid = "\40\41\42\43\44\45\46\47\48\49\50\51\52\53 \54\55\56\57\72\73\74\75\76
\77\100\133\134\135\136\137\138\139\140 \173\174\175\176\n\r\t";
$tok = strtok($string, $invalid);
while ($tok) {
echo "Word=$tok<br>";
$token[]=$tok;
$tok = strtok($invalid);
}
// displays the number of words in the string and the 4th word
echo "Number of token: " . count($token) . "<br>";
echo $token[3];
----
Manual Page -- http://www.php.net/manual/en/function.strtok.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+51681
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+51681&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+51681&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+51681&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+51681&report=yes&reason=useless
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+51681&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+51681&report=yes
Search -- http://master.php.net/manage/user-notes.php