Last active
August 25, 2017 03:58
-
-
Save yeungon/56f27232436db9c161cfa76e69709526 to your computer and use it in GitHub Desktop.
[PHP] - sort out email address _ REGEX
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
$text = "Ngày thử nhất tôi đăng ký một cái email là [email protected], ngày thứ hai tôi đăng ký là [email protected]"; | |
$res = preg_match_all("/[a-z0-9]+[_a-z0-9.-]*[a-z0-9]+@[a-z0-9-]+(.[a-z0-9-]+)*(.[a-z]{2,4})/i",$text,$matches); | |
if ($res) { | |
// array_unique loại bỏ các phần từ nào trùng nhau | |
foreach(array_unique($matches[0]) as $email) { | |
echo $email . ""; | |
} | |
} | |
// Kết quả: | |
// [email protected] | |
// [email protected] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment