开发者

UTF-8, and mbstring extension in php

开发者 https://www.devze.com 2022-12-13 15:45 出处:网络
While I was converting my latin-1 mysql database into utf-8 i came across this article (http://developer.loftdigital.com/blog/php-utf-8-cheatsheet)

While I was converting my latin-1 mysql database into utf-8 i came across this article (http://developer.loftdigital.com/blog/php-utf-8-cheatsheet)

p开发者_高级运维lease note I have successfully converted my database and my app appears to be working/outputting correctly

It the previously mentioned link it says about installing and using the mbstring extension and functions. This doesn't appear to be necessary, is this something i should consider, ignore or have to do?

Thanks in advance!


You will (probably) run into problems when using string manipulation functions now that everything is in UTF-8. You can avoid this if you enable the "mbstring.func_overload" option which will override PHP's built in functions with Mb_* ones (or replace built in functions with Mb_* functions by hand). See this page in the PHP manual


First of all, mbstring is not DB matter, but rather PHPs. And second - yes, you should have this extension if you want to do anything with your strings in PHP - eg comparing or splitting.

The simplest example will be padding string to certain length (like you have an article preview in search list), if you use standard PHP functions, they operate on single bytes and can cut 'through' one UTF character.

You can overload some variables if you're in control of web server. But to make code more portable, I suggest explicitly use mb_* functions. Most of web servers have this extension enabled this days.

0

精彩评论

暂无评论...
验证码 换一张
取 消