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

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -