Zend Framework 应用程序是否需要 mbstring 才能支持 UTF8?

发布于 2024-09-15 10:17:59 字数 1063 浏览 4 评论 0原文

我正在 zend 框架中构建一个 Web 应用程序,需要所有语言的 UTF8 支持。 除了像 stripslashes 之类的功能之外,这似乎工作得很好。

在此 URL 上,他们谈论使用 MBSTRING http://developer.loftdigital.com/blog/php-utf-8- cheatsheet

是否有必要在我的服务器上使用 mbstring 并用 MB 变体替换所有出现的不支持 UTF8 的函数?

Zend Framework不支持UTF8吗? 如果没有,我们就必须将 ZF 代码库中的所有函数替换为 mb_ 替代品,对吧?这是一项不可能完成的任务,因为升级到新的 ZF 会破坏我们的代码。

mail()      -> mb_send_mail()
strlen()    -> mb_strlen()  
strpos()    -> mb_strpos()
strrpos()   -> mb_strrpos()
substr()    -> mb_substr()
strtolower()    -> mb_strtolower()
strtoupper()    -> mb_strtoupper()
substr_count()  -> mb_substr_count()
ereg()      -> mb_ereg()
eregi()     -> mb_eregi()
ereg_replace()  -> mb_ereg_replace()
eregi_replace() -> mb_eregi_replace()   
split()     -> mb_split()

你对此有什么建议,我可能完全错了? 我读到有关使用:

mbstring.func_overload  = 7 ;

自动重载所有函数的内容。

这会破坏不需要 UTF8 的现有应用程序还是会“正常降级”?

I'm building a web app in zend framework that needs UTF8 support for all languages.
This seems to work fine except for functions like stripslashes and such.

On this URL, they talk about using MBSTRING
http://developer.loftdigital.com/blog/php-utf-8-cheatsheet

Is it necessary to use mbstring on my server and replace ALL occurences of UTF8-incapable functions by their MB-variant?

Isn't Zend Framework suppost to support UTF8 ?
If not, we'd have to replace all functions in the ZF-codebase to their mb_ alternatives, right? Which is an impossible task because an upgrade to a new ZF would break our code.

mail()      -> mb_send_mail()
strlen()    -> mb_strlen()  
strpos()    -> mb_strpos()
strrpos()   -> mb_strrpos()
substr()    -> mb_substr()
strtolower()    -> mb_strtolower()
strtoupper()    -> mb_strtoupper()
substr_count()  -> mb_substr_count()
ereg()      -> mb_ereg()
eregi()     -> mb_eregi()
ereg_replace()  -> mb_ereg_replace()
eregi_replace() -> mb_eregi_replace()   
split()     -> mb_split()

What's your advice on this, I might be completely wrong on this?
I read about using:

mbstring.func_overload  = 7 ;

to overload all functions automatically.

Will this break an existing application that doesn't need UTF8 or does it "degrade gracefully"?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

埖埖迣鎅 2024-09-22 10:18:00

Zend Framework 不是支持
支持UTF8吗?

我不知道。例如,只需 grep 搜索 strlen 的代码,但您仍然需要查看代码以确定它是否在非多字节安全的上下文中使用。快速谷歌搜索显示了这个 http://www.iezzi.ch/archives/371 所以看起来ZF 已为 UTF8 应用程序做好准备。

你对此有何建议,我可能会
这完全错误吗?我读到
使用: mbstring.func_overload = 7 ;
这会破坏现有的
不需要 UTF8 或的应用程序
它是否“优雅地降级”?

当然,它也适用于非多字节字符串,并且不会破坏它。但在使用它之前,我建议确保您确实需要它,因为它会降低性能。

Isn't Zend Framework suppost to
support UTF8 ?

I don't know. Just grep through the code searching for strlen for example but you will still need to look at the code to determine if it's used in a context which is not multibyte safe. Quick googling revealed this http://www.iezzi.ch/archives/371 so it seems that ZF is prepared for UTF8 apps.

What's your advice on this, I might be
completely wrong on this? I read about
using: mbstring.func_overload = 7 ;
Will this break an existing
application that doesn't need UTF8 or
does it "degrade gracefully"?

Of course it will work for non-multibyte strings as well and not break it. But before using it I would suggest to make sure that you really need it because it will cost performance.

临走之时 2024-09-22 10:17:59

不要,我只能重复一遍,不要使用 mbstring 重载。它肯定会破坏任何方法,例如依赖 strlen() 返回字节数的方法。 Zend Framework 中的所有组件默认都支持 UTF-8,但如果您指定,也可以处理不同的字符集。这是通过 iconv_* 完成的,它默认内置于 PHP 中,因此不依赖于 mbstring 等额外库。

您必须告诉 Zend Framework 关于 UTF-8 的唯一事情是您的数据库连接,您可以通过 charset 选项简单地完成此操作(请参阅 Zend_Db 或 Zend_Application 文档)。您肯定还想告诉用户代理您通过内容类型标头提供的字符集。并且不要忘记在标签中添加accept-charset =“utf-8”。

Do not, and I can only repeat, do not use mbstring overloading. It will most certainly break any method which, for instance, relies on strlen() returning the number of bytes. All components in Zend Framework expect UTF-8 by default, but can handle different charsets if you tell it to. That is done via iconv_*, which is built into PHP by default, so there are no dependencies on extra libraries like mbstring.

The only thing were you have to tell Zend Framework about UTF-8 is your database connection, which you can simply do via the charset option (see Zend_Db or Zend_Application documentation). You surely also want to tell the user agent which charset you deliver via the content-type header. And don't forget to add accept-charset="utf-8" in your tags.

场罚期间 2024-09-22 10:17:59

我不认为用 mb_string 重载所有函数会很好,
我们都知道 PHP 本身不处理 utf8,因此我们

对数据库和数据库使用类似“SET NAMES utf8”的内容。我们使用 Zendmail + 将编码作为参数传递给它,让 Zend mail 在内部自行管理

另一个例子是 Zend_Validate_StringLength 它有一个名为 encoding 的参数,它使用 iconv 在函数中调用:

 public function setEncoding($encoding = null)
    {
        if ($encoding !== null) {
            $orig   = iconv_get_encoding('internal_encoding');
            $result = iconv_set_encoding('internal_encoding', $encoding);
            if (!$result) {
                require_once 'Zend/Validate/Exception.php';
                throw new Zend_Validate_Exception('Given encoding not supported on this OS!');
            }

            iconv_set_encoding('internal_encoding', $orig);
        }

        $this->_encoding = $encoding;
        return $this;
    }

但您始终会在应用程序中的某些与框架无关的逻辑中使用 mb_string 。

例如昨天我正在对 post & 的 utf8 数组进行排序来自数据库的评论

如果不使用 mb 字符串我就无法完成工作
因为 php 本身不处理 utf8 :(

我喜欢 mb 字符串,它让我的生活更轻松

编辑:
我的意思是在需要时使用 mbstring,并让框架自行管理,我不喜欢自动重载所有函数。

I don't think overloading all the functions with mb_string would be good ,
we all know that PHP doesn't handle utf8 natively so we use something like

"SET NAMES utf8" for the database & we use Zendmail + pass the encoding to it as a parameter to let Zend mail manage it self internally

another example is Zend_Validate_StringLength it had a parameter called encoding and it uses iconv in function called :

 public function setEncoding($encoding = null)
    {
        if ($encoding !== null) {
            $orig   = iconv_get_encoding('internal_encoding');
            $result = iconv_set_encoding('internal_encoding', $encoding);
            if (!$result) {
                require_once 'Zend/Validate/Exception.php';
                throw new Zend_Validate_Exception('Given encoding not supported on this OS!');
            }

            iconv_set_encoding('internal_encoding', $orig);
        }

        $this->_encoding = $encoding;
        return $this;
    }

but you would always use mb_string in your app in some logic which is not related to the framework .

for example yesterday i was sorting a utf8 array of post & comments from a database

i couldn't get the job done without using mb string
because php doesn't handle utf8 natively :(

i love mb string it made my life easier

EDIT :
what i meant to say is use the mbstring whenever you need it , and let the framework manage itself , i don't like overload all functions automatically.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文