SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Enthusiast csweb's Avatar
    Join Date
    Dec 2004
    Location
    UK
    Posts
    59
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Removing Duplicated Emails from a Text file

    I'm storing peoples email who sign up to a news letter in a text file. for some reason some people sign up twice and now I have a massive list with quite a few duplicates, is there any script I could use/make to remove this duplicates?

    Thanks Chris

  2. #2
    Romans 12:2 codyrockx's Avatar
    Join Date
    Jul 2003
    Location
    Newberg, Oregon
    Posts
    422
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    something like this will place them all in array, then remove the duplicates and output them again as if you were saving them
    PHP Code:
    <?php
    $filename 
    'emails.txt';
    $handle fopen($filename,'w+');

    $contents fread($handle,sizeof($filename));
    $emails explode(',',$contents);

    $emails array_unique($emails);
    $contents implode(',',$emails);

    fwrite($handle,$contents);
    fclose($handle);
    ?>
    haven't tested it, although that should work just make sure the file you are taking the emails from has chmod settings set to "766" or "777".
    Codyrobert.com - Designer and Developer

  3. #3
    SitePoint Enthusiast csweb's Avatar
    Join Date
    Dec 2004
    Location
    UK
    Posts
    59
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oh thanks very useful which chmod is only writeable by the server 766?

  4. #4
    Romans 12:2 codyrockx's Avatar
    Join Date
    Jul 2003
    Location
    Newberg, Oregon
    Posts
    422
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    it depends on your installation. the chmod values refer to the permissions for the server,group, and world respectively. because this script would be run from a browser you need the last two to atleast have reading and writing privelages for it to be able to save the modified data.
    Codyrobert.com - Designer and Developer

  5. #5
    SitePoint Enthusiast csweb's Avatar
    Join Date
    Dec 2004
    Location
    UK
    Posts
    59
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    But then cant people just go to youdomain.com/text.txt edit it and click save?

  6. #6
    Romans 12:2 codyrockx's Avatar
    Join Date
    Jul 2003
    Location
    Newberg, Oregon
    Posts
    422
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    no, that only allows a script to be run from your server that will do that; a person could only access that script, running it in the browser and it allows that to edit the file; essentially, the only script you would have to do that would clean up any repeat emails so it would do no harm.
    Codyrobert.com - Designer and Developer

  7. #7
    SitePoint Enthusiast csweb's Avatar
    Join Date
    Dec 2004
    Location
    UK
    Posts
    59
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok I've also made an email validator function, which returns true if an email is valid and false otherwise. How would I make a script that checks every email in the text file (each email on a new line) to see if is valid and delete the email if it is not.

    Chris


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •