PHP regex for $_SERVER["QUERY_STRING"] -


i matching pairs in regex. $pairs[1] contain part before = , $pairs[2] contain part after = .

when gets &startrow should start skips rest , start making pair.

$query= "link=http://abcd.com&efgh&lmkn&startrow=20"  preg_match_all('/(\w+)=([^&startrow]+)/', $query, $pairs); 

the above regex stops @ & not @ &startrow

expected output

$pairs[1][0] = link $pairs[2][0] = http://abcd.com&efgh&lmkn   $pairs[1][1] =startrow $pairs[2][1] =20 

using following regex:

(\w+)=((?:(?!&startrow).)+) 

you able catch both parts separately:

preg_match_all('~(\w+)=((?:(?!&startrow).)+)~', $str, $matches, preg_set_order); 

php output:

array (     [0] => array         (             [0] => link=http://abcd.com&efgh&lmkn             [1] => link             [2] => http://abcd.com&efgh&lmkn         )      [1] => array         (             [0] => startrow=20             [1] => startrow             [2] => 20         )  ) 

php live demo


Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -