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??
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??
This small PHP script will help us to extract the email address from a long paragraph or text. Just copy paste this script and save it as a PHP file (extract.php):
The above script will produce this result:
Email addresses are really tricky to filter using regular expressions because there are so many possible allowable characters. It can be done, but you may have to tweak it some to get exactly what you need.
You could start with something like this:
And then $matches should contain your email address.
Match to a regular expression like -
([A-Za-z0-9-]+)@([A-Za-z0-9])\\.([a-z]{3})
or something similar.Building on mandaleeka's answer, break the string up using a space delimeter then use filter_var to sanitize then validate to see if what remains is a legitimate email address:
based from constantine regex.. works with ip address domain too.