Jump to content

[SOLVED] Extract url from string


casperpaul

Recommended Posts

Hi,

 

I need to extract a url form a another url string.  For example, suppose I have:

 

$a = http://news.google.com/news/url?sa=T&ct=us/0-0-0&fd=R&url=http://www.signonsandiego.com/news/politics/20070504-9999-1n4debate.html&cid=1115939682&ei=2gc7Rsr_IZ3C0gHeiOGyAw

 

How can I write a function to only extract this part:

 

http://www.signonsandiego.com/news/politics/20070504-9999-1n4debate.html&cid=1115939682&ei=2gc7Rsr_IZ3C0gHeiOGyAw

 

Any help is much appreciated.

 

Thanks,

Paul

Link to comment
https://forums.phpfreaks.com/topic/49959-solved-extract-url-from-string/
Share on other sites

Wow that was fast!  Thanks!

 

I have a following question:

 

After running explode, using the same example above, I get the string:

 

http://www.signonsandiego.com/news/politics/20070504-9999-1n4debate.html&cid=1115939682&ei=2gc7Rsr_IZ3C0gHeiOGyAw

 

From here, how get rid of the trailing?

 

&cid=1115939682&ei=2gc7Rsr_IZ3C0gHeiOGyAw

 

 

Thanks,

Paul

 

<?php
$a = "http://news.google.com/news/url?sa=T&ct=us/0-0-0&fd=R&url=http://www.signonsandiego.com/news/politics/20070504-9999-1n4debate.html&cid=1115939682&ei=2gc7Rsr_IZ3C0gHeiOGyAw";
$next_url = substr($a,strpos($a,"&url=")+5);
$query_str = substr($next_url,strpos($next_url,"&cid")+4);

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.