Hello,
I have an email string that sometimes has a name and the email address between <> and sometimes has the email adress right away.
Two examples of the possible value of $address
Joe Doe <[EMAIL PROTECTED]> [EMAIL PROTECTED]
I need to convert this string always to the email address and discard the name to the left of the < character, if the string is already correct (like [EMAIL PROTECTED]) then do not change it, keep it as it is.
I have writen a function to do a for loop and check for the < then copy everything to the end removing the >. I wonder, is there a more efficient, clear way to accomplish this?
Thanks in advace.
One way to do it (untested):
$EmailAddress = preg_match('/<([^>]+)>/', $TestAddress, $MatchList) ? $MatchList[1] : $TestAddress ;
$TestAddress would be the 'Joe Doe <[EMAIL PROTECTED]>' or '[EMAIL PROTECTED]' string, and $EmailAddress *should* be just the email address proper. If you want to validate the email address further, search the archives for email validation:
http://marc.theaimsgroup.com/?l=php-general&r=1&w=2
See http://php.he.net/preg_match
and ternary operators in
http://us2.php.net/language.operators
for more info.
- steve
-- +--------------- my people are the people of the dessert, ---------------+ | Steve Edberg [EMAIL PROTECTED] | | University of California, Davis (530)754-9127 | | Programming/Database/SysAdmin http://pgfsun.ucdavis.edu/ | +---------------- said t e lawrence, picking up his fork ----------------+
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php