search
Homephp教程php手册PHP编码转换在Excel读取中的作用体现

PHP编码转换在Excel读取中的作用体现

Jun 13, 2016 am 11:10 AM
excelpearphpeffectdevelopexistNowusecodingreadConvert

PHP发展了不少,现在pear用起来很方便,其中就有相关的class来读取Excel文件里面的内容,如果不想使用pear的话,可以考虑使用excel_class.php,google一下,可以找到这个class的source code下载,也能找到基本的example code,用起来很方便。

在PHP编码转换时需要注意的是,从Excel里面读取出来的属于UTF-16LE编码,如果在移动应用中使用excel_class,则需要注意,因为通常手机都是支持UTF-8编码,其中就涉及到编码的转换。

例如我使用

echo $return[Sheet2][0][0];

来显示第1行第1列里面的内容,原本内容是“开始”,使用PHP在web上显示的时候也确实是“开始”,但是查看网页的源代码是

开始

其中是为了在网页上显示,24320和22987的十六进制表示则是“开始”的UTF-16LE编码。

那么我们需要做的就是将这个UTF-16LE编码转换为UTF-8编码。
首先打开excel_class.php,找到函数uc2html, 将函数中的代码注释掉,直接将参数返回, 即改函数不做任何操作。

function uc2html($str) {
return $str;
}

接下来使用PHP中提供的函数mb_convert_encoding来将UTF-16LE转换成UTF-8。

echo mb_convert_encoding($return[Sheet2][0][0], 'UTF-8', 'UTF-16LE');

到此,即完成了UTF-16LE到UTF-8的PHP编码转换。


Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function