Re: Parse a string containing name and email

From: Date: Sun, 07 Mar 2010 06:31:07 +0000
Subject: Re: Parse a string containing name and email
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-302591@lists.php.net to get a copy of this message
Don wrote:
Hi, I am pulling email values out of a database and the format is as follows: John Smith<john.smith@somedomain.com> I need to parse the string into two variables as such $name = John Smith $email = john.smith@somedomain.com What would be the easiest way to do this? Thanks. [36] Sun 07.Mar.2010 0:27:35
[kadmin@archangel][~/scripts] cat split <?php $data="John Smith<js@foo.com>"; list($name,$email)=explode("<",str_replace(">","",$data)); echo "$name's email address is $email"; ?> [37] Sun 07.Mar.2010 0:27:40 [kadmin@archangel][~/scripts] php split John Smith's email address is js@foo.com Throw in a foreach() and some data writes or w/e, and you're done. Kevin Kinsey

« previous php.general (#302591) next »