jakebur01 Posted May 6, 2008 Share Posted May 6, 2008 How to I extract just the url part out of a full html link? Example: the $testlink variable contains a html link $testlink = <a href="http://www.testlink.com/">Test Link</a>; How do I get just the http://www.testlink.com/ out of the link? Link to comment https://forums.phpfreaks.com/topic/104392-exploding-a-link/ Share on other sites More sharing options...
Rohan Shenoy Posted May 6, 2008 Share Posted May 6, 2008 <?php $testlink ="<a href=\"http://www.testlink.com/\">Test Link</a>"; $array=explode("href=\"",$testlink); echo substr($array[1],0,strpos($array[1],"\">")); //outputs: http://www.testlink.com/ ?> Link to comment https://forums.phpfreaks.com/topic/104392-exploding-a-link/#findComment-534447 Share on other sites More sharing options...
moselkady Posted May 6, 2008 Share Posted May 6, 2008 You can also try regular expressions: echo ereg_replace("<a href=\"([^\"]+)\".*", "\\1", $testlink); Link to comment https://forums.phpfreaks.com/topic/104392-exploding-a-link/#findComment-534459 Share on other sites More sharing options...
jakebur01 Posted May 6, 2008 Author Share Posted May 6, 2008 how do i cut everything off after the .com, .net. or .org example: http://clickserve.cc-dt.com/link/click?lid=41000346346356262638103 but all i want is the http://clickserve.cc-dt.com Link to comment https://forums.phpfreaks.com/topic/104392-exploding-a-link/#findComment-534749 Share on other sites More sharing options...
GingerRobot Posted May 6, 2008 Share Posted May 6, 2008 Try: <?php $url = 'http://clickserve.cc-dt.com/link/click?lid=41000346346356262638103'; $parts = explode('/',$url); $newurl = $parts[0].'//'.$parts[2]; echo $newurl; ?> Link to comment https://forums.phpfreaks.com/topic/104392-exploding-a-link/#findComment-534771 Share on other sites More sharing options...
moselkady Posted May 7, 2008 Share Posted May 7, 2008 You can try this too: echo ereg_replace("<a href=\"http://([^\"/]+).*", "http://\\1", $testlink); Link to comment https://forums.phpfreaks.com/topic/104392-exploding-a-link/#findComment-534987 Share on other sites More sharing options...
ThYGrEaTCoDeR201 Posted May 7, 2008 Share Posted May 7, 2008 nice examples! Link to comment https://forums.phpfreaks.com/topic/104392-exploding-a-link/#findComment-534991 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.