How to get email address from a long string

2019-01-05 01:16发布

In PHP, I have a string like this:

$string = "user@domain.com MIME-Version: bla bla bla";

How do i get the email address only? Is there any easy way to get the value??

标签: php string email
13条回答
唯我独甜
2楼-- · 2019-01-05 01:57

If the email address is always at the front of the string, the easiest way to get it is simply to split the string on all instances of the space character, and then just take the first value from the resulting array.

Of course, make sure to check it is something resembling an email address before you use it.

See the PHP 'split' function for details.

查看更多
登录 后发表回答