Re: Getting part of a string

From: Date: Sun, 21 Jan 2001 03:42:01 +0000
Subject: Re: Getting part of a string
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-35874@lists.php.net to get a copy of this message
On Sat, Jan 20, 2001 at 09:10:45PM -0500, Website4S@aol.com wrote : > I have a form which users enter their email address, once submitted I need a > way to chop it up and put it in lowercase. So that if a user submits > Website4S@AoL.com I want PHP to throw out Website4S and then make the rest > lowercase so I would get @aol.com > > I know how to get the string to lowercase by using > > $Email1=strtolower($Email); > > My problem is how to get $Email and chop off anything up to the @ and because > people may enter different email providors I have no idea how to get around > it. Anyone have a suggestion I would really appreciate it. The key to your secret is called regular expression. <? $email = "joe.average@downunder.net"; if( eregi( "^([^@]+)@([^@]+)$", $email, $match)) { $email_user = $match[1]; $email_domain = strtolower( $match[2]); echo "$email_user at $email_domain"; } else echo "bad email"; ?> Note, this does not validate if the email is correct; if you need this, take a look at php.net, some of the manual comments talk about email validaten ( whereupon methinks Tom Christiansen email verifier [written in perl] is still the best validator). hope this helps m. -- Markus Fischer, http://josefine.ben.tuwien.ac.at/~mfischer/ EMail: mfischer@josefine.ben.tuwien.ac.at PGP Public Key: http://josefine.ben.tuwien.ac.at/~mfischer/C2272BD0.asc PGP Fingerprint: D3B0 DD4F E12B F911 3CE1 C2B5 D674 B445 C227 2BD0

« previous php.general (#35874) next »