strtok
-
We can tokenize a string in Ruby using the
String#splitmethod along with a regular expression.PHP
$tok = strtok("This is\tan\nexample", " \n\t"); while ($tok !== false) { $tokens[] = $tok; $tok = strtok(" \n\t"); } var_export($tokens); // => array(0 => 'This', 1 => 'is', 2 => 'an', 3 => 'example')
Ruby
p "This is\tan\nexample".split(/[\n\t ]/) # => ["This", "is", "an", "example"]
see also
Looking for Rails or PHP web application development, integration, and training?
Rails for PHP is brought to you by Maintainable Software. Get custom web applications and personalized training from the authors of the book and website.

