PHP strtok() Function
In this chapter you will learn:
- Definition for PHP strtok() Function
- Syntax for PHP strtok() Function
- Parameter for PHP strtok() Function
- Return for PHP strtok() Function
- Example - Split string one by one
Definition
The strtok() function splits a string into smaller strings (tokens).
Syntax
PHP strtok() Function has the following syntax.
strtok(string,split)
Parameter
Parameter | Is Required | Description |
---|---|---|
string | Required. | String to split |
split | Required. | One or more split characters |
Return
PHP strtok() Function returns a string token
Example
In the example below, the first call to strtok() uses the string argument. After that, this function only needs the split argument.
<?php// j a v a 2s . co m
$string = "Hello world. from java2s.com.";
$token = strtok($string, " ");
while ($token != false){
echo "$token\n";
$token = strtok(" ");
}
?>
The code above generates the following result.
Next chapter...
What you will learn in the next chapter:
- Definition for PHP strtolower() Function
- Syntax for PHP strtolower() Function
- Parameter for PHP strtolower() Function
- Return for PHP strtolower() Function
- Example - Convert string to lowercase
Home » PHP Tutorial » PHP String Functions