The Little Guy Posted September 17, 2008 Share Posted September 17, 2008 I need to find text between: q= and an & from a url passed to a variable. but... sometimes there is no ampersand, because the q= is at the end of the URL, so How can I find the q string? if(preg_match("~q=(.+?)&~",$ref,$matches)){ $search = $matches[1]; } my code receives this string as ONE string NOT multiple GET variables Quote Link to comment Share on other sites More sharing options...
DarkWater Posted September 17, 2008 Share Posted September 17, 2008 <?php $ref = "someurl.php?foobar=lol&q=ROFL"; preg_match('/q=(.+?)(?:&|$)/i', $ref, $matches); print_r($matches); Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted September 17, 2008 Author Share Posted September 17, 2008 works! Quote Link to comment Share on other sites More sharing options...
effigy Posted September 18, 2008 Share Posted September 18, 2008 ~(?<=q=)[^&]*~ Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.