PHP uses the Fgetcsv () function for data in CSV format.
Use the following statement
$hd =fopen (' test.csv ', ' R '); $buf =fgetcsv ($HD, 1000, ', ');
Opens a Test.csv formatted file with the contents of the file separated by the "," number.
The first row taken represents an automatic meaning, such as id,messaget,time and so on.
Start with the second line to indicate specific data, such as 1, message, 12:00.
if ($buf [1]== "some Messages") echo "yes";
It is supposed to start with the second line, the output of this statement should be yes, but after the attempt you will find no output.
What is this for?
You can use the strlen () function to compare the lengths of $buf[1] with "messages."
The result of the comparison is not equal.
God, how did this happen? Obviously the second row $buf[1] take out the value is "message" ah, how can length different?
This is related to how your CSV format files are encoded.
How to solve this problem?
First, the function mb_detect_encoding ($buf [1], ' utf-8,euc-cn,assii ') is detected using PHP's character encoding.
If the encoded format is "EUC-CN", then the following statement converts it to the UTF8 encoding format,
Use PHP's character conversion function mb_convert_encoding (), $res =mb_convert_encoding ($buf [1], ' UTF-8 ', ' EUC-CN ').
Compare the result of the conversion $res with the string "message", and you can see that they are finally equal.
http://www.bkjia.com/PHPjc/765066.html www.bkjia.com true http://www.bkjia.com/PHPjc/765066.html techarticle PHP uses the Fgetcsv () function for CSV-like data. Use the following statement $hd =fopen (' test.csv ', ' R '), $buf =fgetcsv ($HD, 1000, ', '); Opens a Test.csv file with the contents of ...