File_get_contents Read xls a garbled piece?

Source: Internet
Author: User
Tags php excel
I put an XLS on the net, the local WPS Open is normal, but with file_get_contents or file () but get a garbled text. $S = Iconv ("Utf-8", "gb2312", $data); or $s =iconv ("gb2312", "Utf-8", $data), all without effect

Ask how to deal with AH.

Thank you!!


Reply to discussion (solution)

That's for sure!
XLS is a binary file, you as a text processing, no problem is strange

That's for sure!
XLS is a binary file, you as a text processing, no problem is strange

Thank you moderator, my PHP code is to download an XLS file, I debug when found to be garbled, the original is binary.
I originally wanted to download the XLS file after processing, and then save it. But download down is garbled, do not know how to handle better? XLS file is much larger than 2M.
Read directly with fopen?

PHP processing XLS files can be used Phpexcel class library

PHP processing XLS files can be used Phpexcel class library

Thank you, can you pass a function directly to the current binary stream into a string?
Because I am currently downloading the data is the XLS binary, the file is also very large, if I have said before, I must first save the XLS file, and then read this XLS file, appear troublesome.
I wonder if there is any way to convert the binary $file---$str that are currently downloaded from the Web into a string?

Turn into a string is also garbled, you can not understand.

Turn into a string is also garbled, you can not understand.

PHP processing XLS files can be used Phpexcel class library

Thank you two bit, but Phpexcel feel really not good ah. The main is the speed is really slow. Or I just contact, still continue to study, is now holding phpexcel example directly into my own xls,3 minutes passed, haven't read, XLS document 2M, about 60,000 lines.

I will describe my present question again:
1, I first in the online curl downloaded an xls file, this time has not been saved, because this XLS file I want to deal with, so I hope that before the save, the inside of the data processing. But under Debug, the XLS file is all garbled.
So I want to ask if there is any way to restore this binary data directly to text at this point, so as to facilitate data processing.

2, assuming that the above ideas can not be achieved, then I only that curl downloaded data is guaranteed to be a Xxx.xls file format, and then use Phpexcel to open, read the XLS file data, but now, I was on the side of the post with Phpexcel read XLS, Now 5 minutes have passed and still not finished reading.

Ask you master, what is the best way to solve?
After all, the 2m document, my file () or file_get_contents just a moment to read, and now the situation even phpexcel eventually read out, but so slow progress has made the data processing lost meaning ...

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

Phpexcel processing small files is OK, processing large files can not expect it to be strong, although a number of caching mechanisms, but for large files are basically the same as fake.

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

Phpexcel processing small files is OK, processing large files can not expect it to be strong, although a number of caching mechanisms, but for large files are basically the same as fake.

Thank you! But my program requires-----data processing and inserting the database all of these auto-complete, where the capture that step to see binary garbled stuck ....


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

Phpexcel processing small files is OK, processing large files can not expect it to be strong, although a number of caching mechanisms, but for large files are basically the same as fake.

Thank you! But my program requires-----data processing and inserting the database all of these auto-complete, where the capture that step to see binary garbled stuck ....

Do not understand what you say the collection is to do. It is still recommended to convert to CSV format, which is actually a fixed-format, recorded text file.

In addition, if you do not apply to third-party libraries to read Excel, then sure you read out is garbled. The stream file is not the same as the record type file.
But after converting to CSV, just do what you want to read.

In addition, if you do not apply to third-party libraries to read Excel, then sure you read out is garbled. The stream file is not the same as the record type file.
But after converting to CSV, just do what you want to read.

Thank you for pointing, because the problem is very urgent, I temporarily changed a kind of thinking to solve.
I said the acquisition is that this XLS file is having PHP directly online to get XLS data and then directly processing the data
(manual cannot intervene), not download to the local computer manually converted to CSV, unless PHP has the XLS-and-CSV conversion code, I looked online, it seems not good to find.


In addition, if you do not apply to third-party libraries to read Excel, then sure you read out is garbled. The stream file is not the same as the record type file.
But after converting to CSV, just do what you want to read.

Thank you for pointing, because the problem is very urgent, I temporarily changed a kind of thinking to solve.
I said the acquisition is that this XLS file is having PHP directly online to get XLS data and then directly processing the data
(manual cannot intervene), not download to the local computer manually converted to CSV, unless PHP has the XLS-and-CSV conversion code, I looked online, it seems not good to find.

It is also possible to convert xls-csv with third-party tools. Find a different language to write the conversion tool, in PHP calls can also.

PHP Excel class, a lot of, very simple, very useful



In addition, if you do not apply to third-party libraries to read Excel, then sure you read out is garbled. The stream file is not the same as the record type file.
But after converting to CSV, just do what you want to read.

Thank you for pointing, because the problem is very urgent, I temporarily changed a kind of thinking to solve.
I said the acquisition is that this XLS file is having PHP directly online to get XLS data and then directly processing the data
(manual cannot intervene), not download to the local computer manually converted to CSV, unless PHP has the XLS-and-CSV conversion code, I looked online, it seems not good to find.

It is also possible to convert xls-csv with third-party tools. Find a different language to write the conversion tool, in PHP calls can also.

Thank you, because at that time to deal with this matter very urgent, so avoid this problem, I avoid reading xls for a way to solve the idea. These days in the study you said PHP xls conversion

  • 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.