×

Welcome to TagMyCode

Please login or create account to add a snippet.
1
0
 
0
Language: PHP
Posted by: Massimo Zappino
Added: Dec 3, 2010 3:32 PM
Views: 124
  1. function tokenizer($string, $pattern = null)
  2.     {
  3.         if ($pattern == null) {
  4.             $pattern = " ";
  5.         }
  6.         $toks = array();
  7.         $string = (string) $string;
  8.         $string = trim($string);
  9.         if (strlen($string) == 0) return array();
  10.         $tok = strtok($string, $pattern);
  11.         while ($tok !== false) {
  12.             $toks[] = $tok;
  13.             $tok = strtok($pattern);
  14.         }
  15.         return $toks;
  16.     }