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.. 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]; ?> 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. 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 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
Archived
This topic is now archived and is closed to further replies.