PHP Use More Than One Delimiter To Split String – String Function

 
    <?php
   $info = "J. G:joe@w3mentor.com|Vancouver, BC";
   // delimiters include colon (:), vertical bar (|), and comma (,)
   $tokens = ":|,";
   $tokenized = strtok($info, $tokens);
   // print out each element in the $tokenized array
   while ($tokenized) {
      echo "Element = $tokenized<br />";
      // Don't include the first argument in subsequent calls.
      $tokenized = strtok($tokens);
   }
?>

Enjoyed this post? Share it!

 

Leave a comment

Your email address will not be published.