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
Share on other sites

This is not a useful but still try

 

<?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";
echo substr($a,strpos($a,"&url=")+5);
?>

Link to comment
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

 

Link to comment
Share on other sites

<?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);

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.