15c01-1.php
来自「介绍PHP5的给类型函数应用」· PHP 代码 · 共 33 行
PHP
33 行
<?php// Define three arrays of data that we wish to write to disk, // each in a similar format:$line1 = array(27, 'Sally had a dog', 0.567, 'a');$line2 = array(42, "See\nJane\nrun", 1.7, 'f');$line3 = array(3, 'Once upon a "mid-day" sunny ...', 3.14, 'p');// Now open a CSV file to write these out to:$csv = fopen('test.csv', 'w');// And put these lines in it as csv: Will output similar to:// 27,"Sally had a dog",0.567,afputcsv($csv, $line1);fputcsv($csv, $line2);fputcsv($csv, $line3);// Now close the file.fclose($csv);// Now let's open it back up to read from it:$readcsv = fopen('test.csv', 'r');// Read in each line, and dump it to the screen ... each line will be// an array holding one entry per CSV value:echo "<pre>";while ($line = fgetcsv($readcsv)) { print_r($line);}echo "</pre>";// Close the file:fclose($readcsv);?>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?