TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   Advanced PHP Programming (http://www.talkphp.com/advanced-php-programming/)
-   -   Hostname Regex (http://www.talkphp.com/advanced-php-programming/3242-hostname-regex.html)

WinSrev 08-15-2008 03:31 PM

Hostname Regex
 
Hey, it's been a while :-P

Kinda have a small issue. I'm trying get the actual hostname of a domain the problem i face is subdomains.

For example, i'm trying to produce a regex that could at least get all the follow to result in domain.com:

sub.domain.com
domain.co.uk
domain.com
sub.domain.co.uk
sub.sub.domain.gov.uk

etc.. Any ideas?

Thanks! ^^

tony 08-15-2008 09:56 PM

are you trying to get the hostnames of your website or all the hostnames that have your word (in this example 'domain') from the Internet?

WinSrev 08-16-2008 10:25 AM

Just a hostname, they are purely examples. The "domain" part could be anything.

Kalle 08-16-2008 12:32 PM

You could use the parse_url() function built into PHP to fetch the domain name =)

PHP Code:

<?php
    $url 
'http://www.talkphp.com/';

    
var_dump(parse_url($url));
?>

Note, on invalid url's parse_url() will return false and throw an E_WARNING, so calling it with the error control operator prefixed (@).


All times are GMT. The time now is 05:26 AM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0