strtok() function in PHP

PHPProgrammingServer Side Programming

The strtok() function is a tokenize string. It returns a string token.

Syntax

strtok(str, split)

Parameters

  • str − The string to split

  • split − Specifies one or more split characters

Return

The strtok() function returns a string token.

Example

The following is an example −

 Live Demo

<?php
   $str = "This is it!";
   $token = strtok($str, " ");

   while ($token !== false){
      echo "$token<br>";
      $token = strtok(" ");
   }
?>

Output

The following is the output −

This<br>is<br>it!<br>
raja
Updated on 26-Dec-2019 09:43:34

Advertisements