strtok() function in PHP


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>

Updated on: 26-Dec-2019

180 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements