我有以下的PHP腳本,它從兩個CSV文件中讀取,在我將數據放入但是表中我需要它輸出到CSV文件的那一刻...PHP輸出到CSV
<?php
$products_file = fopen('Products.csv', 'r');
$manufacturers_file = fopen('Manufacturers.csv', 'r');
$manufacturers = array();
while (($manufacturers_line = fgetcsv($manufacturers_file)) !== FALSE) {
$manufacturers[$manufacturers_line[0]] = $manufacturers_line [1];
}
echo '<table><tr><th>SKU</th><th>Make and Model</th><th>Make and Model</th></tr>';
while (($products_line = fgetcsv($products_file)) !== FALSE) {
echo '<tr><td>'.$products_line[3].'</td><td>';
echo $manufacturers[$products_line[5]];
echo '</td><td>'.$products_line[4].'</td></tr>';
}
echo '</table>';
fclose($products_file);
fclose($manufacturers_file);
?>
如何使用fputcsv來做到這一點?
http://php.net/manual/en/function.fputcsv.php是你所需要的。該功能需要一個文件句柄,並將一個數組女巫保存在一行文件中。 – 2011-03-14 15:19:25