PHP code conversion is a relatively basic point of knowledge in PHP, but for many people who have just started to learn PHP, it may not be too concerned about its importance. And then we'll come to the concrete talk about the role of PHP encoding transformation in Excel reading. I hope we can have a good grasp of it.
PHP developed a lot, now pear is very convenient to use, which has the relevant class to read the contents of the Excel file, if you do not want to use pear, you can consider using Excel_ Class.php,google, you can find this class source code download, you can also find the basic example code, easy to use.
It is important to note that in PHP encoding conversion, the UTF-16LE encoding that is read from Excel, if you use Excel_class in mobile applications, you need to be aware, because the phone is usually supported UTF-8 encoding, which involves the conversion of the encoding.
For example I use
echo $return [sheet2][0][0];
To show the contents of the 1th column in row 1th, the original content is "start", and it is really "start" when using PHP to display on the web, but the source code for viewing the Web page is
& #24320 & #22987
where & #是为了在网页上显示, hexadecimal representation of 24320 and 22987 is the Utf-16le encoding for "start".
So what we need to do is convert this Utf-16le code to UTF-8 encoding.
First open the excel_class.php, find the function uc2html, the code in the function commented out, directly return the parameters, that is, the function does not do anything.
function uc2html ($str) {return $str;}
Next, use the function mb_convert_encoding provided in PHP to convert the Utf-16le to UTF-8.
Echo mb_convert_encoding ($return [sheet2][0][0], ' UTF-8 ', ' utf-16le ');
This completes the PHP code conversion from Utf-16le to UTF-8.