siddscool19 Posted April 17, 2009 Share Posted April 17, 2009 How to get only the hostname from the link? What I want to do is to get only "http://test.com" from "http://test.com/tester" How can we do this? Also can we get only "/tester" from "http://test.com/tester/index.php" Thanks in advance. Quote Link to comment https://forums.phpfreaks.com/topic/154452-solved-get-hostname-from-a-link/ Share on other sites More sharing options...
keeB Posted April 17, 2009 Share Posted April 17, 2009 try http://php.net/pathinfo Quote Link to comment https://forums.phpfreaks.com/topic/154452-solved-get-hostname-from-a-link/#findComment-812100 Share on other sites More sharing options...
siddscool19 Posted April 17, 2009 Author Share Posted April 17, 2009 did not work it has no option for getting hostname only also when i try to get only directory path it gets also the hostname with it Like $url="http://test.com/tester/index.php"; $path_parts=pathinfo($url); echo $path_parts['dirname'], "<br>"; echo $path_parts['basename'], "<br>"; echo $path_parts['extension'], "<br>"; echo $path_parts['filename'], "<br>"; The result is http://test.com/tester index.php php index What I want is to get only /tester in the first output. Quote Link to comment https://forums.phpfreaks.com/topic/154452-solved-get-hostname-from-a-link/#findComment-812102 Share on other sites More sharing options...
keeB Posted April 17, 2009 Share Posted April 17, 2009 How about this one? http://us.php.net/manual/en/function.parse-url.php Quote Link to comment https://forums.phpfreaks.com/topic/154452-solved-get-hostname-from-a-link/#findComment-812111 Share on other sites More sharing options...
siddscool19 Posted April 17, 2009 Author Share Posted April 17, 2009 Thanks a lot dude that works Quote Link to comment https://forums.phpfreaks.com/topic/154452-solved-get-hostname-from-a-link/#findComment-812161 Share on other sites More sharing options...
keeB Posted April 17, 2009 Share Posted April 17, 2009 No problem! Quote Link to comment https://forums.phpfreaks.com/topic/154452-solved-get-hostname-from-a-link/#findComment-812335 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.