Mostafa Elkady
Mostafa Elkady

Reputation: 5801

regex help getting a value from url

i have this

http://news.google.com/news/url?sa=t&fd=R&usg=AFQjCNFyHi2aIJIV7kAlui1Sd_MQGosiBA&url=http://ksa.daralhayat.com/ksaarticle/192445

i want to get the value of url= only

Upvotes: 0

Views: 509

Answers (2)

Fabio Mora
Fabio Mora

Reputation: 5499

For completeness the you can preg_match with that:

/^.*url\=(.*)$/

But you should prefer the parse_url() method that is really faster than a RegEx.

Upvotes: 0

Wrikken
Wrikken

Reputation: 70540

$url = html_entity_decode($url);
$parts = parse_url($url);
parse_str($parts['query'],$params);
echo $params['url'];

Upvotes: 7

Related Questions