Re: [PHP] Parse a string containing name and email

[email protected] (Kevin Kinsey)
Newsgroups php.general
Message-ID <[email protected]>
Don wrote:
> Hi,
> 
> I am pulling email values out of a database and the format is as follows:
> 
> John Smith<[email protected]>
> 
> I need to parse the string into two variables as such
> 
> $name = John Smith
> $email = [email protected]
> 
> 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<[email protected]>";
	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 [email protected]

Throw in a foreach() and some data writes or w/e, and you're done.

Kevin Kinsey
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.