SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    Formerly known as RockNRollPig Shpigford's Avatar
    Join Date
    Dec 2002
    Location
    Denver, CO
    Posts
    2,877
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How would I transfer the contents of this text file into my database?

    I have a client who was using a mailing list script that stored all the addresses in a .txt file with each address separated by a "%". Now I would like to transfer all of those addresses to a MySQL database. What do I need to do to loop through all the addresses and insert them into the database?

  2. #2
    SitePoint Zealot devscripts's Avatar
    Join Date
    Sep 2004
    Location
    ur monitor
    Posts
    175
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    1.fopen the file first sorry.

    2. fread() the file contents
    3. explode() it using % as separator
    4. insert into database.

  3. #3
    SitePoint Zealot devscripts's Avatar
    Join Date
    Sep 2004
    Location
    ur monitor
    Posts
    175
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    heres sample taken from php.net fread

    <?php
    // get contents of a file into a string
    $filename = "/usr/local/something.txt";
    $handle = fopen($filename, "rb");
    $contents = fread($handle, filesize($filename));
    fclose($handle);
    ?>

    now you can use explode here since you said emails separated by % so we do this..

    $emails=explode("%",$contents);

    and you get an array of

    echo $emails[0];
    echo $emails[1];

    and so on. loop it to get all.

    )


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
  •