File_get_contents reading xls garbled characters?

Source: Internet
Author: User
Tags php excel
File_get_contents reading xls garbled characters? I posted an xls on the internet. The local wps is normal, but I got a garbled text using file_get_contents or file. $ S = iconv ("UTF-8", "gb2312", $ data); or $ S = iconv ("gb2312", "UTF-8", $ data); no effect

Ask how to handle it ..

Thank you !!


Reply to discussion (solution)

That's of course!
Xls is a binary file. you can process it as a text file. it's strange that you don't have any problems.

That's of course!
Xls is a binary file. you can process it as a text file. it's strange that you don't have any problems.

Thanks to the moderator. My php code is to download an xls file, and I found it garbled during debugging. it turns out to be binary.
I originally wanted to download the xls file and save it later. But the download is garbled. I don't know how to deal with it? The number of xls files is nearly 2 Mb, which is relatively large.
Can I directly use fopen to read data?

Php can use the PHPExcel class library to process xls files

Php can use the PHPExcel class library to process xls files

Thank you. can I use a function to directly convert the current binary data into a string?
Because the data I downloaded is in the xls binary format and the file size is large, it is troublesome to save it as an xls file and then read it.
I wonder if I can convert the binary $ file --> $ str downloaded from the internet into a string?

Conversion to a string is garbled and you cannot understand it.

Conversion to a string is garbled and you cannot understand it.

Php can use the PHPExcel class library to process xls files

Thank you two, but PHPExcel is really difficult to use. The main reason is that the speed is really slow. Or I just got in touch, and I am still continuing to study. now I just replace my own xls in the PHPExcel example. three minutes have passed and I haven't finished reading it yet. The xls document is 2 MB, about 60 thousand rows.

I will describe my current problem again:
1. I first downloaded an xls file from the Internet curl, but it has not been saved yet, because this xls file is to be processed, so I hope that before it is saved, the data is processed. However, in debug, the xls file is garbled.
Therefore, I would like to ask if there is any way to directly restore the binary data to text at this time to facilitate data processing.

2. assuming that the above idea cannot be implemented, I only need the data downloaded from curl to a xxx.xls file format, and then use PHPExcel to open and read the xls file data, I posted a post and used PHPExcel to read xls. now five minutes have passed and I have not finished reading it yet.

How can I solve this problem?
After all, my file () or file_get_contents just finished reading the 2 M file. now, even if PHPExcel finally reads the file, the slow progress has made data processing meaningless...

It is recommended that you manually convert the file to a CSV file and then write the code for processing, which is much faster than directly processing the XLS file.

PHPEXCEL is fine for processing small files. you can't expect it to be strong in processing large files. although several caching mechanisms are provided, it is basically a virtual setting for large files.

It is recommended that you manually convert the file to a CSV file and then write the code for processing, which is much faster than directly processing the XLS file.

PHPEXCEL is fine for processing small files. you can't expect it to be strong in processing large files. although several caching mechanisms are provided, it is basically a virtual setting for large files.

Thank you! However, my program requires that data collection, data processing, and database insertion are all completed automatically, and the collection step shows that binary garbled characters are stuck ....


It is recommended that you manually convert the file to a CSV file and then write the code for processing, which is much faster than directly processing the XLS file.

PHPEXCEL is fine for processing small files. you can't expect it to be strong in processing large files. although several caching mechanisms are provided, it is basically a virtual setting for large files.

Thank you! However, my program requires that data collection, data processing, and database insertion are all completed automatically, and the collection step shows that binary garbled characters are stuck ....

I don't understand what the collection is. It is still recommended to convert to CSV format. CSV is actually a record-type text file in a fixed format.

In addition, if you do not use a third-party library to read EXCEL files, you must have read garbled text. Stream files and record files are different.
But after converting it to CSV, you can read it as you like.

In addition, if you do not use a third-party library to read EXCEL files, you must have read garbled text. Stream files and record files are different.
But after converting it to CSV, you can read it as you like.

Thanks for your advice. The problem is very urgent. I have changed my mind to solve it.
I am talking about the collection, that is, the xls file has php to directly obtain the xls data online, and then directly process the data.
(Manual intervention is not supported). It is not downloaded to a local computer and converted to csv manually. unless php has xls-> csv conversion code, it seems difficult to find it online.


In addition, if you do not use a third-party library to read EXCEL files, you must have read garbled text. Stream files and record files are different.
But after converting it to CSV, you can read it as you like.

Thanks for your advice. The problem is very urgent. I have changed my mind to solve it.
I am talking about the collection, that is, the xls file has php to directly obtain the xls data online, and then directly process the data.
(Manual intervention is not supported). It is not downloaded to a local computer and converted to csv manually. unless php has xls-> csv conversion code, it seems difficult to find it online.

Conversion XLS-CSV with third-party tools is also possible. Find a write conversion tool in other languages and use PHP to call it.

PHP Excel, a lot of, very simple, very easy to use



In addition, if you do not use a third-party library to read EXCEL files, you must have read garbled text. Stream files and record files are different.
But after converting it to CSV, you can read it as you like.

Thanks for your advice. The problem is very urgent. I have changed my mind to solve it.
I am talking about the collection, that is, the xls file has php to directly obtain the xls data online, and then directly process the data.
(Manual intervention is not supported). It is not downloaded to a local computer and converted to csv manually. unless php has xls-> csv conversion code, it seems difficult to find it online.

Conversion XLS-CSV with third-party tools is also possible. Find a write conversion tool in other languages and use PHP to call it.

Thanks. at that time, it was very urgent to deal with this problem, so I avoided this problem. I avoided reading xls and solved it with another way of thinking. I have been studying the php xls conversion you mentioned in the past few days.

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.