note 19838 deleted from function.fgetcsv by maxim

From: Date: Sat, 10 Aug 2002 20:33:42 +0000
Subject: note 19838 deleted from function.fgetcsv by maxim
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-34789@lists.php.net to get a copy of this message
<?php /* Example: CSV Element Conversion - Read in a CSV File - Init Caps certain columns - Write out to a new CSV File */ $dir = "/websites/fm.lfcity.org/htdocs/csv/"; $file = "mine-MEX00-AC.csv"; $row = 1; $fp = fopen ($file,"r"); while ($line = fgetcsv ($fp, 1000, ",")) { $row++; $num = count ($line); for ($c=0; $c < $num; $c++) { //print $data[$c] . "<br>"; $companies[$row][] = $line[$c]; } } fclose ($fp); // Open Output CSV file $new_file = $dir . "new_" . $file; $fp = fopen($new_file, "w"); foreach($companies as $company){ // Do case conversion on specific columns $company[1] = ucwords(strtolower($company[1])); $company[2] = ucwords(strtolower($company[2])); $company[4] = ucwords(strtolower($company[4])); $company[9] = ucwords(strtolower($company[9])); $company[10] = ucwords(strtolower($company[10])); // Add quotes to lines containing commas for($x=0; $x<=count($company); $x++){ if(strstr($company[$x],",")){ $company[$x] = '"'.$company[$x] .'"'; } } // Make new CSV line $csv_line = implode(",", $company) . "\n"; // Write out new CSV Line entry to CSV file fputs($fp, $csv_line); } fclose($fp); ?>

« previous php.notes (#34789) next »