Re: Simple String Handling
| From: | Anuradha Ratnaweera | Date: | Fri, 22 Dec 2000 15:09:27 +0000 |
| Subject: | Re: Simple String Handling | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-31582@lists.php.net to get a copy of this message | ||
On Fri, 22 Dec 2000, Ignacio Vazquez-Abrams wrote:
> 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"
> >
>
> if (($pos=strpos($input, '.'))!==false)
> {
> $domainminustld=substr($input, 0, $pos+1);
> $tld=substr($input, $pos);
> }
> else
> {
> print("Blah!");
> }
Isn't it
$tld = substr($input, 0, $pos);
^
If you are going for complicated strings, better look into ereg_replace()
Anuradha