1
Anonymous
Stupid question... please answer :)
  • 2004/1/31 3:50

  • Anonymous

  • Posts: 0

  • Since: 0


Hey i've got a stupid PHP question.
I'm trying to figure out how I can tokenize a string to array that's set up like this... the string will look like...

[info1][info2][info3][info4]...

I want to extract each data item between the [,] brackets into seperate members of the array. so the array would like like..
array[0] = info1
array[1] = info2
array[2] = info3
array[3] = info4
...

I know you can do this with ereg() but I am unfamiliar with it and having stared at a book for past 15 minutes I still can't seem to understand how to get it to do what I want. Thanks to whoever can help.

2
Dave_L
Re: Stupid question... please answer :)
  • 2004/1/31 4:11

  • Dave_L

  • XOOPS is my life!

  • Posts: 2277

  • Since: 2003/11/7


$text = '[info1][info2][info3][info4]';
preg_match_all('/[(.*?)]/', $text, $matches);
$foo = $matches[1];

$foo (or $matches[1]) is the desired array.