[thelist] writing to a file PHP (csv)

Andrew Maynes andrew at humanbehaviour.co.uk
Mon Dec 16 16:39:01 CST 2002

Hi Carl this is the $cc (which was an old example I had that did put CC details
into a plain text file, held is a password protected dir :p)  Basically what i
need to do is store the data in a file that then can be imported into Sage (line
50 I think).

$cc="$friends_name; $friends_email; $senders_name; $email";

which is adding data on the same row and not returning to create a new row
(line) as csv file?  for some reason the records are just being inserted on the
same line

-----Original Message-----
From: thelist-admin at lists.evolt.org
[mailto:thelist-admin at lists.evolt.org]On Behalf Of Carl J Meyer
Sent: Monday, December 16, 2002 22:23
To: thelist at lists.evolt.org
Subject: Re: [thelist] writing to a file PHP (csv)


On Mon, 2002-12-16 at 13:12, Andrew Maynes wrote:
> have so far.  However it isn't putting the data in csv format (tab)?
> $FileName="admin/email_list.txt";
> 		$fp = fopen($FileName, "a+");
> 		fputs($fp, "$cc,\n");
> 		fclose($fp);

Without knowing the contents of the variable '$cc', this doesn't tell us
anything at all.  /You/ have to put the data in the right format,
fputs() just writes whatever you give it to the file.  'CSV' format is
just a regular old text file with one-record-per-line, fields
comma-separated.  Here's a quickie function that returns a CSV string
(which you could save to file using your code above), given data in a 2d
array (optionally you can specify the separator, if you want
tab-separated use "\t"):

function makeCSV($data, $sep = ',')
    if(!is_array($data)) { return ''; }
    $ret = '';
    foreach($data as $record)
            { $ret .= join($sep, $record) . "\n"; }
    return $ret;


More information about the thelist mailing list