search
Homephp教程php手册基于php iconv函数的使用详解

基于php iconv函数的使用详解

Jun 13, 2016 am 11:49 AM
iconvmodulephpunixwindDownusefunctionbased onInstallofcompileDetailed explanationneed

unix下安装PHP的module,需要重新编译PHP,Windows下安装模板,只需将php.ini里的配置打开相应的dll就可,例如,需要加入gb库的支持,需要如下设置:
extension_dir = "C:/ipaddr/php/extensions/"
(注意,建议写全地址,并且后面加上/,很多时候是因为这里设置不对,才导致无法加载其它模块的dll的)
再打开
extension=php_gd2.dll
但如果是安装iconv.dll,按上面方法,打开php_iconv.dll后,还是无法开启iconv模块,需要如下配置:
a.上iconv的官方下载站点
http://ftp.gnu.org/pub/gnu/libiconv/
下面Windows版的iconv文件:libiconv-1.9.1.bin.woe32.zip
将这文件解压,将bin/下面的charset.dll,iconv.dll,iconv.exe拷贝到c:/windows/ (或其它的系统PATH中)
(ipaddr提醒你,这步是必须的,php_iconv.dll也是调用GNU的iconv库的,所以,先要安装GNU的iconv库)

b.开启php.ini里面的php_iconv.dll

c.重启Apache,再在phpinfo();检测是否开启iconv。
最近在做一个程序,需要用到iconv函数把抓取来过的utf-8编码的页面转成gb2312, 发现只有用iconv函数把抓取过来的数据一转码数据就会无缘无故的少一些。 让我郁闷了好一会儿,去网上一查资料才知道这是iconv函数的一个bug。iconv在转换字符"—"到gb2312时会出错
解决方法很简单,就是在需要转成的编码后加 "//IGNORE" 也就是iconv函数第二个参数后.如下:
以下为引用的内容:
iconv("UTF-8","GB2312//IGNORE",$data)
ignore的意思是忽略转换时的错误,如果没有ignore参数,所有该字符后面的字符串都无法被保存。

这个iconv()这个函数,在php5中是内置的.谢谢.

列子

复制代码 代码如下:


echo $str= '你好,这里是卖咖啡!';
echo '
';

echo iconv('GB2312', 'UTF-8', $str);      //将字符串的编码从GB2312转到UTF-8
echo '
';

echo iconv_substr($str, 1, 1, 'UTF-8');   //按字符个数截取而非字节        
print_r(iconv_get_encoding());            //得到当前页面编码信息

echo iconv_strlen($str, 'UTF-8');         //得到设定编码的字符串长度

//也有这样用的

   $content = iconv("UTF-8","gbk//TRANSLIT",$content);
?>

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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)