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

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -