RE: [PHP] Simple String Handling
| From: | Maxim Maletsky | Date: | Fri, 22 Dec 2000 15:01:23 +0000 |
| Subject: | RE: [PHP] Simple String Handling | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-31576@lists.php.net to get a copy of this message | ||
why not to use explode()?
$domain = "PHPBeginner.com";
$domain = str_replace($domain, 'www.', ''); // in case you wish to get rid
of these www...
$domain = explode('.', $domain);
echo $domain[0]; // prints PHPBeginner
now the $domain is an array, means that $domain[1] would be 'com'
and if $domain[2] exists, means that the domain had more then just .com,
maybe .co.jp or something ...
Cheers,
Maxim Maletsky
-----Original Message-----
From: Ignacio Vazquez-Abrams [mailto:ignacio@openservices.net]
Sent: Friday, December 22, 2000 11:55 PM
To: o.cook@etoncollege.org.uk
Cc: php-general@lists.php.net
Subject: Re: [PHP] Simple String Handling
On Fri, 22 Dec 2000 o.cook@etoncollege.org.uk wrote:
> I am trying to do some handling on a string which contains a domain name.
I
> can successfully get the TLD but am having less success getting the domain
> name.
>
> My code is:
>
> <?
> $tld = strstr ($input, '.');
> print $tld;
> ?>
>
> Given:
> $input="something.co.uk" ---> $tld=".co.uk" OK
> $input="something.com" -----> $tld=".com" OK
>
> I would also like to get the domain name such that:
>
> $input="something.co.uk" ---> $domain="something"
> $input="something.com" -----> $domain="something"
>
> Would someone be kind enough to point me in the correct direction?
>
> Thank you,
>
> Ollie
>
> ---
> Do radioactive cats have 18 half-lives?
>
> http://pgpkeys.mit.edu:11371/pks/lookup?op=get&search=0x53D29567
> ---
>
if (($pos=strpos($input, '.'))!==false)
{
$domainminustld=substr($input, 0, $pos+1);
$tld=substr($input, $pos);
}
else
{
print("Blah!");
};
--
Ignacio Vazquez-Abrams <ignacio@openservices.net>
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
For additional commands, e-mail: php-general-help@lists.php.net
To contact the list administrators, e-mail: php-list-admin@lists.php.net