0

WHAT I HAVE SO FAR:

This is what i've created so far. It's writing in to .txt file and with a different format that i want to change.

Code:

<?php
    $myfile = fopen("emaillist.txt", "a+");
    $txt = $_POST['country'] . " -- " . $_POST['email'] . "\n";
    fwrite($myfile, $txt);
    fclose($myfile);

    header("Location: http://www.myredirectlocation.com");
?>

So basically with this code i'm storing registered emails. As of now my emails are stored like this in a .txt file:

USA -- email1@something.com

USA -- email2@something.com

Canada -- email3@something.com

WHAT I NEED:

I want to write into .csv or .xls file instead of .txt file.

And also i want it to make columns for each country and write in seperate rows. So it will look like this:

USA | Canada | Australia

email1@something.com | email2@something.com | email3@something.com
rbr94
  • 2,227
  • 3
  • 23
  • 39
Roberts Šensters
  • 585
  • 1
  • 7
  • 23
  • 1
    Sidenote: Are you sure you don't want to use a database for this? Files are a lot of work and storing emails in a text file, well.. let's only hope you've kept that under a heavy lock. – Funk Forty Niner Oct 26 '16 at 13:22
  • Yea, i just want a .csv file. I will need it to import in to another program anyway. – Roberts Šensters Oct 26 '16 at 13:23
  • 1
    Well, if you're planning on using another program and may be db-related, you're working too hard. You can use a LOAD DATA INFILE in MySQL http://dev.mysql.com/doc/refman/5.7/en/load-data.html, just saying. See also http://php.net/manual/en/function.fputcsv.php and http://stackoverflow.com/questions/4249432/export-to-csv-via-php – Funk Forty Niner Oct 26 '16 at 13:24
  • To help you with this: You can use a tab separator and just change the extension to `.csv`. See also https://phpexcel.codeplex.com/ – Funk Forty Niner Oct 26 '16 at 13:27

0 Answers0