Greenguy's Board


Go Back   Greenguy's Board > Programming & Scripting
Register FAQ Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread Display Modes
Prev Previous Post   Next Post Next
Old 2006-10-18, 02:43 AM   #12
QuickDraw
Heh Heh Heh! Lisa! Vampires are make believe, just like elves and gremlins and eskimos!
 
Join Date: Jan 2006
Posts: 72
Here's a function I use to get only the domain from a URL.. I think that's what you're after? Just pass it a url and it will return the domain.

Code:
function getdomain($url)
{
    // patterns we need to match
    $pattern_hostname = '/^(http:\/\/)?([^\/]+)/i';
    $pattern_domain = '/[^\.\/]+\.[^\.\/]+(\.[^\.\/]{2})?$/';
    // extract hostname from URL string
    @preg_match($pattern_hostname, $url, $matches);
     $hostname = $matches[2];
    // extract sld.tld(.cctld if exists)
    @preg_match($pattern_domain, $hostname, $matches);
    $domain = $matches[0];
    return $domain;
}
The only thing is.. it can't differentiate between a domain and an IP - if you pass it an IP, it gives you the last 2 octets as the domain. It would be easy enough to validate that before or after you use the function though.

Hope this helps..
QD

Last edited by QuickDraw; 2006-10-18 at 02:55 AM..
QuickDraw is offline   Reply With Quote
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 08:34 AM.


Mark Read
Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
© Greenguy Marketing Inc