Jump to content

[SOLVED] I need to extract the domain name out of the hostname?


oni-kun

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.