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..

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];
?>

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.

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.