Hey guys, I am trying to tokenize a string into an array, can someone take what I have now and show me how to do this?

<?php

$string = "This is an example string";
$tok = strtok($string," ");

while ($tok) {
echo "$tok<br>";
$tok = strtok(" ");
}

?>

this outputs:
This
is
an
example
string

I would like all of those words to be put into an array but I can't figure it out.

Thanks,

Ben LeMasurier

    Check the manual entry on preg_split. It's way more powerful than split, strtok, or explode. Of course split or explode might also do what you want. If the forum butchers this code its just a copy of the example in the manual for preg_split anyway.

    // split the phrase by any number of commas or space characters,
    // which include " ", \r, \t, \n and \f
    $keywords = preg_split ("/[\s,]+/", "hypertext language, programming");

      Write a Reply...