# Check for duplicate names in text file

**URL:** <https://forum.kirupa.com/t/check-for-duplicate-names-in-text-file/276335>\
**Category:** Uncategorized\
**Created:** [November 25, 2008, 10:36pm UTC](https://forum.kirupa.com/t/check-for-duplicate-names-in-text-file/276335 "2008-11-25T22:36:03Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![dru\_nasty](https://avatars.discourse-cdn.com/v4/letter/d/90db22/32.png) [@dru\_nasty](https://forum.kirupa.com/u/dru_nasty)\
**Post date:** [November 25, 2008, 10:36pm UTC](https://forum.kirupa.com/t/check-for-duplicate-names-in-text-file/276335/1 "2008-11-25T22:36:03Z")

</div>

I’ve got a form that submits email addresses to a text file.  
I need the same script that appends these emails to this text file, to check for duplicate emails in the text file and do something if there is a duplicate.

Here’s the code I have now:

```php

$filename = "emails.txt";

$fd = fopen ($filename, "a") or die ("Can't open $filename");
$fname = $email;
$fout = fwrite ($fd, "$fname
");
fclose($fd);

header("Location: index.php?msg=success");
exit();

```

So i’ve already got the emails adding to the text file separate by new lines. I just need some type of if/else to check if an email is already in there, and if not, add the email. I started reading up on explode but it’s the end of the day and I’m fried 😉

Thanks.
