Summary of common PHP operations for processing CSV table files

Source: Internet
Author: User
CSV files store table data in plain text, so we can easily read and write CSV data through PHP arrays, here, let's take a look at the common operations of PHP to process CSV table files: to edit an online Excel table, the parsing of the Excel xls file format is a problem, after all, this is the private patent format of Microsoft Office.
To do this, use the common csv (Comma Separated Value, Comma-Separated Value) format.
Various office software can recognize csv tables, which are actually tables separated by specific delimiters (such as commas.
For PHP, fgetcsv reads the csv table and returns an array,
Then foreach outputs


CSV table rules:
1. separate the content of cells in each row with commas.
2. if the content of a cell contains a comma, the content of the cell will be enclosed in quotation marks.
3. if the content of a cell contains quotation marks:
(1) the quotation marks are not at the beginning or end. the content of this cell is not enclosed in quotation marks.
(2) when the quotation marks are at the beginning or end, the content of the cell will be enclosed in quotation marks, and the original quotation marks at the beginning and end will be escaped.

Read/write CSV

 

Save as an independent file
Download. php:

  Download csv files

Test. php:

  

Automatically save the csv file to the specified location

  

For more information about common PHP operations for processing CSV table files, see The PHP Chinese website!

In this step, several lines of code can be implemented, which is very simple.The workload mainly lies in the browser front-end. we recommend that you use jQuery to perform DOM and AJAX operations,To achieve fine-grained double-click cell editing like phpMyAdmin, it is not difficult to submit AJAX,Or $ ("form"). serialize () once the entire table is written, and AJAX can also be submitted.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.