I have input string from users. this input from users are unpredictable. it's mean user can input any string as they like. I would like to filter the input that match following pattern and return it as an array
These following string pattern should works:
product=bag, product=tshirt, product=shoes
product=bag status=sold, product=jeans, product=shoes
product=all
I would like the output as array like below :
Array(
[0] => Array
(
[product] => bag
[status] => sold
)
[1] => Array
(
[product] => jeans
)
[2] => Array
(
[product] => shoes
)
)
I guess it can be achieved by use preg_match_all() beside explode. Anyone can give me example using preg_match_all ? or any other ways are ok for me as long as the best method.
$string = 'product=bag status=sold, product=tshirt, product=shoes';
$m = preg_match_all('/needregexrulehere/', $string, $matches);