Re: strstr

From: Date: Fri, 27 Feb 2004 15:59:44 +0000
Subject: Re: strstr
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-179006@lists.php.net to get a copy of this message
Jakes wrote:
I got this out the manual: <?php $email = 'user@example.com'; $domain = strstr($email, '@'); print $domain; // prints @example.com ?> how do I get the "user" ranther than "@example.com"Thanks
I would do something like this: $email = "yourname@example.com"; if (preg_match("/^(.*)\@(.*)$/", $email, $matches)) { // $matches[0] contains the original $email $user = $matches[1]; $domain = $matches[2]; } echo $user . "<br />" . $domain; Check out the manual for more info on preg_match(): http://www.php.net/manual/en/function.preg-match.php -- Regards, Ben Ramsey http://benramsey.com http://www.phpcommunity.org/wiki/People/BenRamsey

« previous php.general (#179006) next »