etrader Posted December 28, 2010 Share Posted December 28, 2010 In a script links are captured from the internet by $link, then display it by echo $link The links have the general format of http://domain.com/something/filename.html I am looking for a simple way to display capture some elements from $link and display "domain.com" and "filename" In other words, I need a code to remove other parts of the link provided by $link Quote Link to comment https://forums.phpfreaks.com/topic/222796-dividing-a-link-function/ Share on other sites More sharing options...
dragon_sa Posted December 28, 2010 Share Posted December 28, 2010 This is quite tricky to do because of the large number of domain options available and also the number of subdirectories it could go into, logic could be something like this -explode based on the "/" -then search the array for values with a "." and put them into new array -sum the new array and use the first and last values just incase some subdirectory names have "." -then for the filename i would explode "." on the last value and use the first value in that array Quote Link to comment https://forums.phpfreaks.com/topic/222796-dividing-a-link-function/#findComment-1152054 Share on other sites More sharing options...
johnny86 Posted December 28, 2010 Share Posted December 28, 2010 I would use PHPs parse_url() function: <?php print_r(parse_url("http://domain.com/something/filename.html")); /* Array ( [scheme] => http [host] => domain.com [path] => /something/filename.html ) */ Now it's easy to pick up stuff from that array. And parsing the path for the information you need isn't that difficult. Quote Link to comment https://forums.phpfreaks.com/topic/222796-dividing-a-link-function/#findComment-1152069 Share on other sites More sharing options...
QuickOldCar Posted January 2, 2011 Share Posted January 2, 2011 I posted just what you need in another post. http://www.phpfreaks.com/forums/php-coding-help/getting-the-path/msg1506898/#msg1506898 Quote Link to comment https://forums.phpfreaks.com/topic/222796-dividing-a-link-function/#findComment-1153796 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.