Home  >  Article  >  Backend Development  >  PHP的小技艺[转]

PHP的小技艺[转]

WBOY
WBOYOriginal
2016-06-13 10:56:24961browse

PHP的小技巧[转]
PHP的小技巧

好象,大多时候,我们对于字符串的比较都是采用了 strtolower或者strtoupper之后,再判断是否相等。只是这样就需要转换两次。大多时候,我们是针对字符集转换的时候才会这样,比如判断参数传进来是否utf-8,这5个字符的写法,可就多了,比如UTF-8,Utf-8,utf-8等,那我们怎么办呢?strtolower?strupper?不需要啦。。
strncasecmp($a,$b,$length)就可以了。。
如果返回是0则相等,那我们怎么判断呢?
strncasecmp($str,'utf-8',5) == 0那么,传入的参数就是utf8的,是否很方便呢?
只是这些函数我们平时不太用得到,我看到这个函数的用法却是在 yii framework,他在处理事件的时候,判断前两个字符是否为 on 的时候,就是这样判断的。我也因此学到了一招。

http://www.neatstudio.com/show-1477-1.shtml

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:php断点上载Next article:3款国产PHP SNS程序推荐