$h = fopen('csv.csv', 'w') or die("Can't open csv.csv");csv.csv 檔案位置同該 php 檔案所在位置。
foreach ($arrays as $array) {
fputcsv($h, $array);
}
fclose($h) or die("Can't close csv.csv");
輸出 CSV 到畫面
$h = fopen('php://output', 'w') or die("Can't open php://output");
foreach ($arrays as $array) {
fputcsv($h, $array);
}
fclose($h) or die("Can't closephp://output");
輸出 CSV 到暫存
ob_start();讀取一般檔案
$h = fopen('php://output', 'w') or die("Can't open php://output");
foreach ($arrays as $array) {
fputcsv($h, $array);
}
fclose($h) or die("Can't closephp://output");
$output = ob_get_contents();
ob_end_clean();
$h = fopen('csv.csv', 'r') or die("Can't open csv.csv");超快讀取一般檔案
while ($string = fgets($h, 1024)) {
...
}
fclose($h) or die("Can't close csv.csv");
$s = file_get_contents('csv.csv');讀取 CSV 檔案
$h = fopen('csv.csv', 'r') or die("Can't open csv.csv");
while ($array = fgetcsv($h)) {
...
}
fclose($h) or die("Can't close csv.csv");
沒有留言:
張貼留言