From a8d1242292174b7316d9f9b3133a1d18f80de4a2 Mon Sep 17 00:00:00 2001 From: PJ Date: Sun, 12 Nov 2017 23:58:55 +1100 Subject: [PATCH] More efficient PHP code based on original MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - $path defined so the code works from anywhere in a framework folder structure - file is loaded to an “associative array” instead of a standard array. The prior approach had to search through entire array to find email address. This approach can use the key index. --- README.md | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 31a4608..1bd81e3 100644 --- a/README.md +++ b/README.md @@ -31,14 +31,16 @@ Available as [PyPI module](https://pypi.python.org/pypi/disposable-email-domains True ``` -**PHP** contributed by @txt3rob and @deguif +**PHP** contributed by [@txt3rob](https://github.com/txt3rob), [@deguif](https://github.com/deguif) and [@pjebs](https://github.com/pjebs) ```php -function is_temp_mail($mail) { - $mail_domains_ko = file('disposable_email_blacklist.conf', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); - - //Need to ensure the mail contains an @ to avoid undefined offset - return in_array(explode('@', $mail)[1], $mail_domains_ko); +function is_disposable_email($email) { + $path = realpath(dirname(__FILE__)) . '/disposable_email_blacklist.conf'; + $mail_domains_ko = file($path, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); + $mail_domains_ko = array_combine($mail_domains_ko, array_fill(0,count($mail_domains_ko), null)); + $domain = mb_strtolower(explode('@', trim($email))[1]) + return (isset($mail_domains_ko[$domain]) || array_key_exists($domain, $mail_domains_ko)); } + ``` **Ruby on Rails** contributed by @MitsunChieh