<?php
$text = "Sample text for testing:
abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ
0123456789 +-.,!@#$%^&*();\/|<>'
12345 -98.7 3.141 .6180 9,000 +42
555.123.4567 +1-(800)-555-2468
foo@demo.net bar.ba@test.co.uk
www.demo.com http://f...content-available-to-author-only...o.uk/
http://r...content-available-to-author-only...r.com/foo.html?q=bar
mail@mail.ru waka@wak.rc.uk";
function grabEmail($text) { //между названием функции и () не ставится пробел.
$emailRegexp = '/[\w-\.]+@[a-z\.-]+/';
$matches = [];
$count = preg_match_all($emailRegexp, $text, $matches, PREG_SET_ORDER
); foreach ($matches as $emails) {
$mail[] = $emails[0];
echo "$emails[0]\n";
}
return $mail;
}
grabEmail($text);
PD9waHAKZXJyb3JfcmVwb3J0aW5nKC0xKTsKCiR0ZXh0ID0gIlNhbXBsZSB0ZXh0IGZvciB0ZXN0aW5nOgphYmNkZWZnaGlqa2xtbm9wcXJzdHV2d3h5eiBBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWgowMTIzNDU2Nzg5ICstLiwhQCMkJV4mKigpO1wvfDw+JwoxMjM0NSAtOTguNyAzLjE0MSAuNjE4MCA5LDAwMCArNDIKNTU1LjEyMy40NTY3CSsxLSg4MDApLTU1NS0yNDY4CmZvb0BkZW1vLm5ldAliYXIuYmFAdGVzdC5jby51awp3d3cuZGVtby5jb20JaHR0cDovL2YuLi5jb250ZW50LWF2YWlsYWJsZS10by1hdXRob3Itb25seS4uLm8udWsvCmh0dHA6Ly9yLi4uY29udGVudC1hdmFpbGFibGUtdG8tYXV0aG9yLW9ubHkuLi5yLmNvbS9mb28uaHRtbD9xPWJhcgptYWlsQG1haWwucnUgd2FrYUB3YWsucmMudWsiOwoKZnVuY3Rpb24gZ3JhYkVtYWlsKCR0ZXh0KSB7IC8v0LzQtdC20LTRgyDQvdCw0LfQstCw0L3QuNC10Lwg0YTRg9C90LrRhtC40Lgg0LggKCkg0L3QtSDRgdGC0LDQstC40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