Guest User

Untitled

a guest
Sep 18th, 2018
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. function extract_emails($str){
  2. // This regular expression extracts all emails from a string:
  3. $regexp = '/([a-z0-9_\.\-])+\@(([a-z0-9\-])+\.)+([a-z0-9]{2,4})+/i';
  4. preg_match_all($regexp, $str, $m);
  5.  
  6. return isset($m[0]) ? $m[0] : array();
  7. }
  8.  
  9. $test_string = 'This is a test string...
  10.  
  11. test1@example.org
  12.  
  13. Test different formats:
  14. test2@example.org;
  15. <a href="test3@example.org">foobar</a>
  16. <test4@example.org>
  17.  
  18. strange formats:
  19. test5@example.org
  20. test6[at]example.org
  21. test7@example.net.org.com
  22. test8@ example.org
  23. test9@!foo!.org
  24.  
  25. foobar
  26. ';
  27.  
  28. print_r(extract_emails($test_string));
Add Comment
Please, Sign In to add comment