oni-kun Posted August 8, 2009 Share Posted August 8, 2009 Hello. I have a script which currently uses.. $fullhost = gethostbyaddr($ip); To get the host and it returns usually something long like.. d11.22.33.44.bschi.host.com .. I use $host = preg_replace("/^[^.]+./", "*.", $fullhost); and it seems make it.. "*.bschi.host.com" but I just want.. "host.com" How do I do this? I tried for hours last night to use strchr and strrpos etc but it always game out wrong.. how to I ignore everything before host.tld? Thank you! This is not an important application, so it can be basic.. Quote Link to comment https://forums.phpfreaks.com/topic/169350-solved-i-need-to-extract-the-domain-name-out-of-the-hostname/ Share on other sites More sharing options...
watsmyname Posted August 8, 2009 Share Posted August 8, 2009 Hello. I have a script which currently uses.. $fullhost = gethostbyaddr($ip); To get the host and it returns usually something long like.. d11.22.33.44.bschi.host.com .. I use $host = preg_replace("/^[^.]+./", "*.", $fullhost); and it seems make it.. "*.bschi.host.com" but I just want.. "host.com" How do I do this? I tried for hours last night to use strchr and strrpos etc but it always game out wrong.. how to I ignore everything before host.tld? Thank you! This is not an important application, so it can be basic.. try this <?php $url="d11.22.33.44.bschi.host.com"; preg_match("/^(http:\/\/)?([^\/]+)/i",$url, $matches); $host = $matches[2]; preg_match("/[^\.\/]+\.[^\.\/]+$/", $host, $matches); echo $matches[0]; ?> Quote Link to comment https://forums.phpfreaks.com/topic/169350-solved-i-need-to-extract-the-domain-name-out-of-the-hostname/#findComment-893598 Share on other sites More sharing options...
oni-kun Posted August 8, 2009 Author Share Posted August 8, 2009 try this <?php $url="d11.22.33.44.bschi.host.com"; preg_match("/^(http:\/\/)?([^\/]+)/i",$url, $matches); $host = $matches[2]; preg_match("/[^\.\/]+\.[^\.\/]+$/", $host, $matches); echo $matches[0]; ?> Works perfect! Thanks. I can now put a [whois] autogenerated link beside the host, it's useful for my project. Quote Link to comment https://forums.phpfreaks.com/topic/169350-solved-i-need-to-extract-the-domain-name-out-of-the-hostname/#findComment-893599 Share on other sites More sharing options...
watsmyname Posted August 8, 2009 Share Posted August 8, 2009 try this <?php $url="d11.22.33.44.bschi.host.com"; preg_match("/^(http:\/\/)?([^\/]+)/i",$url, $matches); $host = $matches[2]; preg_match("/[^\.\/]+\.[^\.\/]+$/", $host, $matches); echo $matches[0]; ?> Works perfect! Thanks. I can now put a [whois] autogenerated link beside the host, it's useful for my project. anytime bro, If that solved your problem, mark your topic as solved Quote Link to comment https://forums.phpfreaks.com/topic/169350-solved-i-need-to-extract-the-domain-name-out-of-the-hostname/#findComment-893610 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.