please can someone help me with this duplicate check feature. I'm still pretty fresh when it comes to PHP, so please excuse me if this is a simple fix.
I store a list of email addresses in a file called list.txt. Here is the contents of the file (each on a new line):
bob@foo.com sam@bar.com tracy@foobar.com
Now I have a function (not working) that should check if the email is in the list:
function is_unique($email) { $list = file('list.txt'); foreach($list as $item){ if($email == $item){ return false; die(); } } return true; }
When I call a function in this test with an existing email address, it still returns true:
if( is_unique(' bob@foo.com ') ) { echo "Email is unique"; } else { echo "Duplicate email"; } // Returns true even though bob@foo.com is in the list
I appreciate any input.
source share