Php extracts strings from csv files. The fgetcsv () function is required for php Data in csv format. The fgetcsv () function is used for php Data with csv format in the file.
Use the following statement
Export hd1_fopen('test.csv ', 'r ');
$ Buf = fgetcsv ($ hd, 1000 ,',');
Open a file in test.csv format. separate the content with.
The first line indicates the automatic meaning, such as id, messaget, and time.
Start from the second line to indicate specific data, such as 1, message.
If ($ buf [1] = "some messages") echo "yes ";
It is reasonable to say that from the second line, the output result of this statement should be yes, but you will find no output after trying.
Why?
You can use the strlen () function to compare the length of $ buf [1] and "Message.
The comparison results are not equal.
God, how can this problem occur? The value obtained from the second line $ buf [1] is "message". how can the length be different?
This is related to the encoding method of your csv file.
How can this problem be solved?
First use php character encoding detection function mb_detect_encoding ($ buf [1], 'utf-8, EUC-CN, asci '),
If the obtained encoding format is "EUC-CN", then the following statement converts it to utf8 encoding format,
Use the php character conversion function mb_convert_encoding (), $ res = mb_convert_encoding ($ buf [1], 'utf-8', 'euc-cn ').
Compare the conversion result $ res with the string "message", then we can find that they are finally equal.
Aggregate () function. Use the following statement to export hd1_fopen('test.csv ', 'r'); $ buf = fgetcsv ($ hd, 1000,', '); open a file in test.csv format, in the file...