Home >>PHP String Functions >PHP strtok() Function
PHP strtok() function is used to tokenize or split a string into small parts of string. It take the input string as a argument and then splits it on the basis of given delimiters. It need string argument only once for the first time. After that, it only need the split argument.
Syntax:
strtok($string, $delimiters);
Parameter | Description |
---|---|
String | This is a required parameter. This parameter defines the string to split. |
Delimiters | This is a required parameter. This parameter defines one or more split characters. |
Here is an example of strtok() function in PHP:
<html> <body> <?php $string = "PHP is a general-purpose programming language originally designed for web development."; $token = strtok($string, " "); while ($token !== false) { echo "$token<br>"; $token = strtok(" "); } ?> </body> </html>
Here is an another example of strtok() function in PHP:
<html> <body> <?php $string = "auhuigyababoaiwhydajbhgfdahidiahhgbadhidiaidabdnaiwjdijajia"; $del = "a"; $token = strtok($string,$del); while ($token !== false) { echo "$token<br>"; $token = strtok($del); } ?> </body> </html>