fork(3) download
  1. <?php
  2.  
  3. $text = "Sample text for testing:
  4. abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ
  5. 0123456789 +-.,!@#$%^&*();\/|<>'
  6. 12345 -98.7 3.141 .6180 9,000 +42
  7. 555.123.4567 +1-(800)-555-2468
  8. foo@demo.net bar.ba@test.co.uk
  9. www.demo.com http://f...content-available-to-author-only...o.uk/
  10. http://r...content-available-to-author-only...r.com/foo.html?q=bar
  11. mail@mail.ru waka@wak.rc.uk";
  12.  
  13. function grabEmail($text) { //между названием функции и () не ставится пробел.
  14. $emailRegexp = '/[\w-\.]+@[a-z\.-]+/';
  15. $matches = [];
  16. $count = preg_match_all($emailRegexp, $text, $matches, PREG_SET_ORDER);
  17. foreach ($matches as $emails) {
  18. $mail[] = $emails[0];
  19. echo "$emails[0]\n";
  20. }
  21. return $mail;
  22. }
  23.  
  24. grabEmail($text);
Success #stdin #stdout 0.01s 20568KB
stdin
Standard input is empty
stdout
foo@demo.net
bar.ba@test.co.uk
mail@mail.ru
waka@wak.rc.uk