在PHP中使用UTF-8字符集-是否需要mb函数? [英] Using UTF-8 charset with PHP - are mb functions required?

查看:77
本文介绍了在PHP中使用UTF-8字符集-是否需要mb函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这几天,我一直在努力将PHP代码从latin1转换为UTF-8.我已经阅读了两个主要解决方案,要么用内置的多字节函数替换单字节函数,要么在php.ini文件中设置mbstring.func_overload值.

These past few days I've been working toward converting my PHP code base from latin1 to UTF-8. I've read the two main solutions are to either replace the single byte functions with the built in multibyte functions, or set the mbstring.func_overload value in the php.ini file.

但是后来我在堆栈溢出时遇到了 this 线程,在这里thomasrutter的帖子似乎表示只要UTF-8编码了脚本和字符串文字,多字节函数实际上就不是UTF-8所必需的.

But then I came across this thread on stack overflow, where the post by thomasrutter seems to indicate that the multibyte functions aren't actually necessary for UTF-8, as long as the script and string literals are encoded in UTF-8.

我没有找到任何其他证据证明这是否正确,如果事实证明我不需要将我的代码转换为mb_functions,那将是一个实时的节省者!任何人都可以对此有所了解吗?

I haven't found any other evidence whether this is true or not, and if it turns out I don't need to convert my code to the mb_functions then that would be a real time saver! Anyone able to shed some light on this?

推荐答案

据我所知,只要您的所有数据都是utf-8中的100%,这意味着用户输入,数据库以及如果文件中包含特殊字符,则对PHP文件本身进行编码-对于搜索和比较操作,这是 true true .正如@ntd所指出的,当在包含多字节字符的字符串上运行时,非多字节的strlen()将产生错误的结果.

As far as I understand the issue, as long as all your data is 100% in utf-8 - and that means user input, database, and also the encoding of the PHP files themselves if you have special characters in them - this is true true for search and comparison operations. As @ntd points out, a non-multibyte strlen() will produce wrong results when run on a string that contains multibyte characters.

是一篇有关编码基础的好文章.

THis is a great article on the basics of encoding.

这篇关于在PHP中使用UTF-8字符集-是否需要mb函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆