Created
May 3, 2014 01:06
-
-
Save madeinnordeste/3750d295fa6e1afc2929 to your computer and use it in GitHub Desktop.
PHP - Get emails address from string
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function extract_emails($str){ | |
$regexp = '/([a-z0-9_\.\-])+\@(([a-z0-9\-])+\.)+([a-z0-9]{2,4})+/i'; | |
preg_match_all($regexp, $str, $m); | |
return isset($m[0]) ? $m[0] : array(); | |
} | |
$test_string = 'This is a test string... | |
[email protected] | |
Test different formats: | |
[email protected]; | |
<a href="[email protected]">foobar</a> | |
<[email protected]> | |
strange formats: | |
[email protected] | |
test6[at]example.org | |
[email protected] | |
test8@ example.org | |
test9@!foo!.org | |
foobar'; | |
print_r(extract_emails($test_string)); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment