Page 1 of 1

simple preg_match_all

Posted: Tue Dec 14, 2010 5:16 am
by malcolmboston
Hi Guys,

Ive been banging my head against a wall for the last half hour trying to parse the following string

Code: Select all

[item=14][category=7][brand=2][item=15][item=2]
and return it like so

Code: Select all

array[0] = 'item=14';
array[1] = 'category=7';
array[2] = 'brand=2';
can anyone help me with the regex pattern?

Cheers

Re: simple preg_match_all

Posted: Tue Dec 14, 2010 11:05 am
by AbraCadaver
At its simplest not taking variations into account:

Code: Select all

preg_match_all('/\[([^\]]+)\]/', '[item=14][category=7][brand=2][item=15][item=2]', $matches);
print_r($matches[1]);