Data Reading functions:
GetData (= (, "r "))! = ())! ===( => [] = Mb_convert_encoding (, "UTF-8", "gbk"); [] =
The Chinese string read is found to be null ....
Solution: Replace the fgetcsv function with the custom _ fgetcsv function.
_ Fgetcsv (
Fgetcsv can't read Chinese
SetLocale (Lc_all, ' ZH_CN ') has been set, but sometimes it is not possible to read the Chinese in the CSV file, why? It seems to be related to the system system!
------Solution--------------------
Document encoding and
Example The code is as follows:Copy code Function get_csv_contents ($ file_target ){$ Handle = fopen ($ file_target, 'r ');While ($ data = fgetcsv ($ handle, 1000 ,",")){ $ Num = count ($ data );Echo " $ num fields in line $ row: n ";$ Row
Fgetcsv can't read Chinese
SetLocale (Lc_all, ' ZH_CN ') has been set, but sometimes it is not possible to read the Chinese in the CSV file, why? It seems to be related to the system system!
------Solution--------------------
Document encoding and
This article to introduce to you about PHP in the Fgetcsv function in the php5.2.8 data incomplete problem resolution, I hope this article will be helpful to you friends.
The problem resolves the data is incomplete, there is an empty fieldI checked
In other windows versions The code is as follows:Copy code # Open the File.If ($ handle = fopen ("test.csv", "r "))! = FALSE ){# Set the parent multidimen1_array key to 0.$ Nn = 0;While ($ data = fgetcsv ($ handle, 0 ,","))! = FALSE ){ //
This article introduces how to solve the problem of incomplete data of the fgetcsv function in php in php5.2.8. I hope this article will help you.
The data parsed by the problem is incomplete and there are blank fields.I found a bug in php5.2.8 on
But on the server, many use Linux server, the source program uses UTF-8, so it is easy to produce character encoding problems.If you just transcode the CSV file to a UTF-8, so there is no problem on the Windows server,In RedHat5.5, if the content of
PHP's own function fputcsv can be used to print the report (Excel) function. If your report format requirements are not very high, then fputcsv is a good choice. It performs efficiently and does not require a third-party library, which is convenient
Solution when the array element obtained by fgetcsv is a null string
// The uploaded CSV file, which is usually GBK encoded in Excel,
// While the source code is UTF-8, transcoding is required
Article to share an article about PHP fgetcsv windows and Linux compatibility issues, have encountered the problem of students can refer to the next.
Setting area: Simplified Chinese, UTF-8 encoding
The code is as follows
Copy Code
PHP processes CSV tables, using fgetcsv and fputcsv to convert between arrays and CSV
Array csv
To edit an online Excel table, parsing the Excel xls file format is a problem. after all, this is the private patent format of Microsoft Office.
To do
But on the server, many use Linux server, the source program uses UTF-8, so it is easy to produce character encoding problems.
If you just transcode the CSV file to a UTF-8, so there is no problem on the Windows server,
In RedHat5.5, if the
But on the server, many use Linux server, the source program uses UTF-8, so it is easy to generate character encoding problems.
If you just transcoding the CSV file to UTF-8, then there is no problem on the Windows Server,
On RedHat5.5, in an
The data parsed by the problem is incomplete and there are blank fields.I found a bug in php5.2.8 on the Internet.The solution is to use a UDF. The code is as follows:Copy code Function _ fgetcsv (& $ handle, $ length = null, $ d = ',', $ e = '"'
Prototype Fgetcsv (resource FP, int length [, String delimiter [, String enclosure [, String escape]])The explanation for enclosure is the character that surrounds the field.Refer to the http://blog.ifeeline.com/217.html description:Fields that
Company A server timed to pull the media report data every day, found that each time the Chinese data obtained is empty, found that the downloaded CSV file Chinese is normal, manually re-run the discovery is normalThe default area for Linux is now
The CSV file that is uploaded, usually edited by Excel, is GBK encoded,
While the source code is UTF-8, transcoding processing is required
File_put_contents ($new _file, Iconv (' GBK ', ' UTF-8 ', file_get_contents ($new _file)));
About the Fgetcsv function
Fgetcsv (Resource fp,int length [, String delimiter,
String Enclosure,
Escape]])
Please explain the red part. Write an example.
What does Green do?
Share to:
more
------Solution--------------------
$s
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.