PHP字符串长度无strlen() [英] PHP String Length Without strlen()

查看:149
本文介绍了PHP字符串长度无strlen()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

只要浏览最新版本的PHP程式码标准,就会发现我的眼球:



http://svn.php.net/viewvc/php/php-src/trunk/CODING_STANDARDS?revision = 296679& view = markup



编码标准#4声明编写处理字符串的函数时,请务必记住PHP保存length属性,并且不应该使用strlen()...



计算。我一直使用strlen,也许只是晚了,但是如何你在PHP中访问字符串的内置length属性?

解决方案

他们在谈论 C函数,而不是PHP函数。 C函数将在第一个 \0 后停止计数,但PHP字符串可以包含 \0 结束。


Just browsing over the latest release of the PHP coding standards, and something caught my eye:

http://svn.php.net/viewvc/php/php-src/trunk/CODING_STANDARDS?revision=296679&view=markup

Coding standard #4 states that "When writing functions that deal with strings, be sure to remember that PHP holds the length property of each string, and that it shouldn't be calculated with strlen()..."

I've ALWAYS used strlen, and maybe it's just late, but how do you access the built-in length property of a string in PHP?

解决方案

They're talking about the C function, not the PHP function. The C function will stop counting after the first \0, but PHP strings can contain \0 elsewhere other than the end.

这篇关于PHP字符串长度无strlen()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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