Here's my function:
function checkForDuplicates($items, $checkitem) { $rows = explode("\n", $items); foreach($rows as $item) { if($item === $checkitem) return TRUE; } return FALSE; } I've confirmed that its returns are accurate and work properly. Here's where the function gets called and I run into an issue:
$email = sanitizeInput($_POST['email']); $email = strtolower($email); $emails = file_get_contents('emails.txt'); if(checkForDuplicates($emails, $email) == FALSE); { $emailFile = fopen('emails.txt','a') or die ('Sorry. Subscriptions are disabled for the time being.'); fwrite($emailFile, $email."\n"); fclose($emailFile); } No matter what I input, it writes to the file either way. I can't possibly understand why such a simple comparison isn't working.
$itemsand $checkitem` would be helpful. Otherwise there's not enough here to help youif (trim($item) === $checkitem)and see if the behaviour improves.