preg match - PHP preg_match how to get from string begin "charcter=" and end with "&" -
i novice in regular expressions.
i have:
$str = 'manufacturer=1,2,3&brand=5,4&filter=29-31+48-46,47&price=150-700'; $find = 'filter'; // example. can price or brand or if (strpos($str, $find) !== false) { $matches = array(); preg_match('/' . $find . '=???/', $str, $matches); var_dump($matches); }
??? represent, regular expressions must use , how can parse string data separately preg_match use like:
[0] = 29-31+48-46,47 // data parsed "filter=" "&" character
i cant use explode or similar command because positions of parameter in string not fixed.
thank!
don't use regex, wrong tool job. use parse_str()
:
$str = 'manufacturer=1,2,3&brand=5,4&filter=29-31+48-46,47&price=150-700'; parse_str( $str, $array); echo $array['filter'];
this prints:
29-31 48-46,47
Comments
Post a Comment