How to get email address from a long string

前端 未结 13 1999
情书的邮戳
情书的邮戳 2020-11-27 04:29

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 a

13条回答
  •  伪装坚强ぢ
    2020-11-27 04:46

    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.

提交回复
热议问题