Training, Open Source
computer languages


PerlPHPPythonMySQLApache / TomcatTclRubyJavaC and C++LinuxCSS 

Search our site for:
Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
Handling Comman Separated Variables in PHP

Posted by admin (Graham Ellis), 1 September 2002
Here's a sample page that adds a record to a CSV file;  the code is fairly straightforward.   Reading back CSV wouldn't be quite so easy ... if it weren't for the fgetcsv function that does all the work for you.   Remember "There's a function to do that" is the common cry in PHP.

Code:
<?php

$fields = array("G Ellis",'"Hillside", The Spa',"Melksham, Wilts","SN12 6QL");
$fh = fopen("csvodemo.txt","a");

$outfields = array();
foreach ($fields as $now) {
       $copy = addslashes($now);
       array_push ($outfields,$copy);
       print "$now<br>";
       }

fputs($fh,'"'.implode('","',$outfields).'"'."\n");


fputs($fh,"This is a test\n");

fclose($fh);

?>




This page is a thread posted to the opentalk forum at www.opentalk.org.uk and archived here for reference. To jump to the archive index please follow this link.


WELL HOUSE CONSULTANTS LTD.: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 707126 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho