Skip to content

Instantly share code, notes, and snippets.

@yeungon
Last active August 25, 2017 03:58
Show Gist options
  • Save yeungon/56f27232436db9c161cfa76e69709526 to your computer and use it in GitHub Desktop.
Save yeungon/56f27232436db9c161cfa76e69709526 to your computer and use it in GitHub Desktop.
[PHP] - sort out email address _ REGEX
$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