casperpaul Posted May 4, 2007 Share Posted May 4, 2007 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 More sharing options...
taith Posted May 4, 2007 Share Posted May 4, 2007 $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'; $a=explode('&url=',$a); $a=$a[1]; Link to comment https://forums.phpfreaks.com/topic/49959-solved-extract-url-from-string/#findComment-245244 Share on other sites More sharing options...
jitesh Posted May 4, 2007 Share Posted May 4, 2007 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 https://forums.phpfreaks.com/topic/49959-solved-extract-url-from-string/#findComment-245246 Share on other sites More sharing options...
casperpaul Posted May 4, 2007 Author Share Posted May 4, 2007 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 https://forums.phpfreaks.com/topic/49959-solved-extract-url-from-string/#findComment-245251 Share on other sites More sharing options...
taith Posted May 4, 2007 Share Posted May 4, 2007 $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'; $a=explode('&url=',$a); $a=$a[1]; $a=explode('&cid=',$a); $a=$a[0]; Link to comment https://forums.phpfreaks.com/topic/49959-solved-extract-url-from-string/#findComment-245253 Share on other sites More sharing options...
jitesh Posted May 4, 2007 Share Posted May 4, 2007 <?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 https://forums.phpfreaks.com/topic/49959-solved-extract-url-from-string/#findComment-245256 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.