I need to filter some email address based on the domain name : Basically if the domain name is yahoo-inc.com, facebook.com, baboo.com .. (and a few others) the function should do something and if the domain is different it should do something else . The only way I know to do this is to use a pattern/regex with preg_match_all and create cases/conditions for each balcklisted domain (e.g if domain = yahoo-inc) do this elseif (domain == facebook.com ) do this ... etc but I need to know if there is a more simple/concis way to include all the domains that I want to filter in a single variable/array and then apply only 2 conditions (e.g if email is in black list {do something } else {do something else}
3条回答 默认 最新
- dougang1965 2011-02-27 23:04关注
Extract the domain portion (i.e. everything after the last '@'), down case it, and then use
in_array
to check whether it's in your blacklist:$blacklist = array('yahoo-inc.com', 'facebook.com', ...); if (in_array($domain, $blacklist)) { // bad domain } else { // good domain }
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报