maddali Posted February 15, 2010 Share Posted February 15, 2010 Hi folks, I was wondering if there is any code that can get the url's that's in a webpage.... here is the page I'm referring to....I need this url http://hdl.handle.net/1920/5657 ,which is in http://omars.gmu.edu/items/show/2536... Quote Link to comment https://forums.phpfreaks.com/topic/192153-get-url-from-a-webpage/ Share on other sites More sharing options...
newbtophp Posted February 15, 2010 Share Posted February 15, 2010 <?php $file = file_get_contents("http://omars.gmu.edu/items/show/2536"); preg_match("/<div class=\"element-text\">http:\/\/([a-z0-9\/\.]*)<\/div>/i", $file, $matches); echo $matches[0]; ?> Quote Link to comment https://forums.phpfreaks.com/topic/192153-get-url-from-a-webpage/#findComment-1012685 Share on other sites More sharing options...
maddali Posted February 15, 2010 Author Share Posted February 15, 2010 It worked...Thanks Can the url in the file_get_contents be replaced with $_SERVER['REQUEST_URI'],so that I get a dynamic function which get the Identifier's url of the current page.... Quote Link to comment https://forums.phpfreaks.com/topic/192153-get-url-from-a-webpage/#findComment-1012699 Share on other sites More sharing options...
maddali Posted February 15, 2010 Author Share Posted February 15, 2010 <?php $tem=$_SERVER['REQUEST_URI']; echo "$tem"; $file=file_get_contents("$tem"); preg_match("/<div class=\"element-text\">http:\/\/([a-z0-9\/\.]*)<\/div>/i",$file,$matches); $temp=$matches[0]; echo $temp; I'm trying to write a code that takes the current url and get the url link in that webpage.I'm sure I went wrong somewhere in the line 4,where file_get_contents should accept the current url of $tem.Can somebody correct the code please Thanks Quote Link to comment https://forums.phpfreaks.com/topic/192153-get-url-from-a-webpage/#findComment-1012789 Share on other sites More sharing options...
newbtophp Posted February 16, 2010 Share Posted February 16, 2010 Access it like pagename.php?url=http://omars.gmu.edu/items/show/2536 <?php $url = strip_tags($_GET['url']); if(isset($url)){ $file = file_get_contents($url); preg_match("/<div class=\"element-text\">http:\/\/([a-z0-9\/\.]*)<\/div>/i", $file, $matches); echo $matches[0]; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/192153-get-url-from-a-webpage/#findComment-1013288 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.