如何从长字符串中获取电子邮件地址 [英] How to get email address from a long string
本文介绍了如何从长字符串中获取电子邮件地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在 PHP 中,我有一个这样的字符串:
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??
推荐答案
如果不确定空格分隔的字符串的哪一部分是电子邮件地址,可以将字符串用空格分隔并使用
If you're not sure which part of the space-separated string is the e-mail address, you can split the string by spaces and use
filter_var($email, FILTER_VALIDATE_EMAIL)
在每个子串上.
这篇关于如何从长字符串中获取电子邮件地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文