php - regular expression parse url parameter -


i'm having trouble retrieving url parameter string using regular expressions:

an example string be

some text , http://google.com/?something=this&tag=yahoo.com , more text, , able find yahoo.com this.

the caveat need ensure string begins http://google.com, , not search &tag=(.*)

preg_match("/google\.com\/.*&tag=(.*) $/", $subject, $matches)

i'm hoping matches google.com followed anything, followed &tag= followed space. goal parse out of tag= values google.com urls.

is there better way accomplish this?

update:

so have new regex: /google\.com\/.*(tag=.*)/ i'm not sure how end on space after url

get friendly parse_url() function!

$pieces = parse_url('some text http://google.com/?something=this&tag=yahoo.com , whatever'); $query = explode('&', $pieces['query']);  parse_str($pieces['query'], $get); array_walk($get, function(&$item){     if (!$sp = strpos($item, ' ')) return;     $item = substr($item, 0, $sp); });  var_dump($get); // woo! 

edit: johnathan parse_str() function.


Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -