Zend_Validate_StringLength 编码?

发布于 2024-11-26 02:26:53 字数 217 浏览 1 评论 0原文

在 Zend Framework 中,Zend_Validate_StringLength 有一个编码属性,可用于在不同字符集之间进行转换(它在字符串上使用 iconv_set_encoding)。

为什么这部分是 StringLength 验证器类的一部分?我应该将其与字符串长度字段检查一起使用以强制执行 UTF-8 吗?

In Zend Framework, Zend_Validate_StringLength has an encoding property that can be used to convert between different character sets (it uses iconv_set_encoding on the string).

Why is this part of the StringLength validator class? Should I use this with my string length field checks to enforce UTF-8?

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

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

发布评论

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

评论(2

如痴如狂 2024-12-03 02:26:53

PHP 中的字符串长度是保存字符串所需的字节数。一些编码使用多个字节(例如两个)来存储单个字符。

因此,如果您使用以多个字节存储某些字符的编码(例如Unicode UTF-8),则需要使用此编码来正确确定字符串长度。
如果使用默认编码设置,可能会得到不准确的结果。

然而,我相信所有 Zend 组件的默认值都是 UTF-8,这是 Web 应用程序中事实上的标准。遗憾的是,这还不是 PHP 的默认设置。

String lengths in PHP are the number of bytes taken to save the string. Some encodings use multiple bytes (e.g. two) to store single character.

Therefore, if you use encoding storing some of the characters in multiple bytes (e.g. Unicode UTF-8), you need to use this encoding to properly determine string length.
If you use the default encoding settings, you may get inaccurate results.

However, I believe the default for all Zend components is UTF-8, which is the de facto standard in the web applications. Pity, this is not the default one for PHP (yet).

月亮是我掰弯的 2024-12-03 02:26:53

实际上它使用iconv_set_encoding只是为了测试当前服务器是否支持指定的$encoding。实际的比较是使用iconv_strlen()进行的。

不确定我能回答你的第二个问题。如果您需要验证字符串长度 - 您需要使用此验证器。

Actually it uses iconv_set_encoding only to test if current server supports specified $encoding. The actual comparison is made with iconv_strlen().

Not sure I can get your second question. If you need to validate strings length - you need to use this validator.

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