I have a string as
$email_string='Aslam Doctor <aslam.doctor@gmail.com>';
From which I want to extract Name & Email using PHP? so that I can get
$email='aslam.doctor@gmail.com';
$name='Aslam Doctor'
Thanks in advance.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
As much as people will probably recommend regular expression I’d say use explode().
Explode splits the string up in several substrings using any delimiter.
In this case I use ‘ <‘ as a delimiter to immediately strip the whitespace between the name and e-mail.
rtrim() will trim the ‘>’ character from the end of the string.