Introduction to the CSV file:
CSV is a common, relatively simple file format that is widely used by users, businesses, and science. The most widespread application is the transfer of tabular data between programs, which themselves operate in incompatible formats (often in private and/or non-canonical formats). Because a large number of programs support some kind of CSV variant, at least as an optional input/output format.
For example, a user might need to exchange information, from a database program that stores data in a private format, to a spreadsheet with a completely different data format. Most likely, the database program can export data as "CSV", and then the exported CSV file can be imported by a spreadsheet program.
"CSV" is not a single, well-defined format (although RFC 4180 has a commonly used definition). In practice, therefore, the term "CSV" refers to any file that has the following characteristics:
Plain text, using a character set such as ASCII, Unicode, EBCDIC, or GB2312;
Consists of records (typically one record per line);
Each record is delimited by a delimiter as a field (a typical delimiter has commas, semicolons, or tabs; sometimes separators can include optional spaces);
Each record has the same field sequence.
There are many CSV variants under these regular constraints, so CSV files are not completely interoperable. However, these mutations are very small and there are many applications that allow the user to preview the file (which is possible because it is plain text) and then specify delimiters, escape rules, and so on. If a particular CSV file is too large to mutate beyond the support of a particular receiving program, it is often advisable to manually check and edit the file, or to fix the problem with a simple program. Therefore, in practice, the CSV file is very convenient.
This article is a detailed analysis of the contents of PHP read CSV file, need to refer to the friend
Read data from all rows in a CSV file at once
<?php $file = fopen (' windows_2011_s.csv ', ' R '); while ($data = Fgetcsv ($file)) {//reads a single line of content//print_r ($data) per CSV;//This is an array, to get each data, access the array subscript can $goods_list[] = $data;} Print_r ($goods _list);/* foreach ($goods _list as $arr) { if ($arr [0]!= "") { echo $arr [0]. " <br> "; }} */Echo $goods _list[2][0]; Fclose ($file);? >
Reads a row of data from a CSV file
<?phpfunction Get_file_line ($file _name, $line) { $n = 0; $handle = fopen ($file _name, ' R '); if ($handle) { while (!feof ($handle)) { + + $n; $out = Fgets ($handle, 4096); if ($line = = $n) break; } Fclose ($handle); } if ($line = = $n) return $out; return false;} Echo get_file_line ("Windows_2011_s.csv", 10);? >
Read CSV file number of rows (line interval)
<?phpfunction get_file_line ($file _name, $line _star, $line _end) {$n = 0; $handle = fopen ($file _name, "R"); if ($handle) {while (!feof ($handle)) {+ + $n; $out = Fgets ($handle, 4096); if ($line _star <= $n) {$ling [] = $out; } if ($line _end = = $n) break; } fclose ($handle); } if ($line _end== $n) return $ling; return false;} $AA = Get_file_line ("Windows_2011_s.csv", 11, 20); From line 11th to line 20th, foreach ($aa as $BB) {echo $bb. <br> ";}?