function stripdomain($string)
                if(stristr($string, "co."))
                                $string = ereg_replace(".co.", ".",
                $end = strrpos($string, ".");
                $string = substr($string, 0, $end);
                while(strchr($string, "."))
                                $start = strpos($string, ".");
                                $string = substr($string, $start+1);
                return $string;

There we go.  This one also parses .co.uk, which frustrated me there for a
minute, but oh well, I'm over it.  I don't believe there are any others that
will slip by this, but of course I can't be certain.

Give it a shot, see if it does what you need.  I tested it with:

It returned with "soon"

Ryan Marrs
Web Developer
Sandler & Travis Trade Advisory Services, Inc.
248.474.7200 x 183
248.474.8500 (fax)

-----Original Message-----
From: heilo [mailto:[EMAIL PROTECTED]] 
Sent: Friday, January 24, 2003 1:27 PM
Subject: Re: [PHP-DB] function needed


I hope I understood you right... I would use PCREs:


function getdomainname($string)
    $pattern = '#(([[:alnum:]]+)(\.))?(.+)(\.)([[:alnum:]]+)#i';
    $replace = '\\4';
    return preg_replace($pattern, $replace, $string);


echo getdomainname($var);




> Hey
> I'm looking and wondering for a function, as i'm trying to do something,
> here it is.
> I'm using the SSI call :
> <!--#echo var="HTTP_HOST" -->.
> to get the domain name I am on. this will output
> www.domain.com.
> I would like to use PHP in order to take this string, the output, and cut
> the "www." and the ".com" from it, so only the "domain" will remain.
> ofcourse we can also have situations whith ".org" and ".net" and even
> there's no "www." but the main thing I need is to remove whats
> after the second dot and before the first dot, along with the dots.
> I don't mind writing all the posibilities to the function, ie, all the
> possible extenstions that the function may need to cut, I just need it to
> take
> the text from the SSI, and cut everything but the "domain" part, which is
> the address itself.
> what would be the best way to do it?
> thank you!!

PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to