simple preg_match_all

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

simple preg_match_all

Post 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
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: simple preg_match_all

Post 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]);
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Post Reply