Php strtok
From w3cyberlearnings
Contents |
PHP function strtok
This function splits a string into smaller strings.
Syntax strtok
- string: string to split.
- split: specifies the string characters token delimiters.
strtok(string, split);
Example 1
- Returns string one piece at a time, and with each subquent call will returning the next piece.
This is usually great for memory usage.
<?php $mystring = "I will not go to any places without you."; $token = strtok($mystring, " "); while ($token != false) { echo "$token <br/>"; $token = strtok(" "); } ?>
Output
I will not go to any places without you.
Example 2
- Using strtok to split the URL GET values
<?php $mystring = "?id=49&list=action&owner=job"; $token = strtok($mystring, "&"); while ($token != false) { echo "$token <br/>"; $token = strtok("&"); } ?>
Output
?id=49 list=action owner=job