(Original) How to deal with the solution to the Excel (CSV) file to import the database! !

xiaoxiao2021-03-06  71

Specific solution, there are a lot on the network, I also go to phpe.net to find a php2csv class, but it provides a little bug, and it is too complicated, I accidentally go to PHP.NET to check the information. I saw this function. Please take a look at the information below. Then I will discuss with you! !

-----------------------------------------

FGetcsv

(PHP 3> = 3.0.8, php 4) FGETCSV - read from the file pointer and parse the CSV field

Description Array

Fgetcsv (int Handle, Int Length [, String Delimiter [, String Enclosure]])

Similar to FGETS (), only FGETCSV () resolve read rows and finds a field in the CSV format and then returns an array containing these fields. The default value of the third parameter DELIMITER is a comma. The default value of the optional parameter enclosure is dual quotation marks. Delimiter and Enclosure are limited to a character. If more than one character, only the first character is used.

Note: The Enclosure parameter is PHP 4.3.0 new.

Handle must be a valid file pointer that successfully opened through FOPEN (), POPEN () or FSOCKOPEN ().

Length must be greater than the maximum length of the CVS file (in order to process the end character).

FGETCSV () Returns false when FGETCSV (), including the end of the file.

Note: The blank line in the CSV file will be returned to an array containing a single null field and will not be used as an error.

Example 1. Read and display the entire content of the CSV file

$ Num Fields in line $ row:
/ n"; $ ROW ; for ($ C = 0; $ C <$ Num; $ C ) {Print $ DATA [$ C]. "
/ n ";}} fclose ($ handle);?>

-----------------------------------------

Save Excel as a comma-divided CSV file, which is a common way to process Excel import to the mysql database.

The FGETCSV () function is specifically used to process the CSV file. I think many friends should understand many friends. Processing CSV files can be so simple. When importing content, only need

For ($ c = 0; $ c <$ num; $ c ) {print "Here to insert data"

} Is ok! Simple! !

If there is still a problem. Please come out! !

转载请注明原文地址:https://www.9cbs.com/read-120275.html

New Post(0)