PHPstrncasecmp字符串比较的小技巧_php技巧
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了PHPstrncasecmp字符串比较的小技巧_php技巧,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1542字,纯文字阅读大概需要3分钟。
内容图文
![PHPstrncasecmp字符串比较的小技巧_php技巧](/upload/InfoBanner/zyjiaocheng/260/bf472cdbf5314f979cb397ae49f4ec94.jpg)
strncasecmp($a,$b,$length)就可以了。。
如果返回是0则相等,那我们怎么判断呢?
strncasecmp($str,'utf-8',5) == 0那么,传入的参数就是utf8的,是否很方便呢?
只是这些函数我们平时不太用得到,我看到这个函数的用法却是在 yii framework,他在处理事件的时候,判断前两个字符是否为 on 的时候,就是这样判断的。我也因此学到了一招。
strncasecmp Definition and Usage
定义和用法
The strncasecmp() function compares two strings.
strncasecmp()函数的作用是:比较字符串的前n个字符(大小写不敏感)。
This function returns:
这个函数将返回下列值:
0 - if the two strings are equal
0 – 如果字符串相等
<0 - if string1 is less than string2
<0 – 如果string1小于string2
>0 - if string1 is greater than string2
>0 – 如果string1大于string2
Syntax
语法
strncasecmp(string1,string2,length)
Parameter参数 | Description描述 |
---|---|
string1 | Required. Specifies the first string to compare 必要参数。指定参与比较的第一个字符串对象 |
string2 | Required. Specifies the second string to compare 必要参数。指定参与比较的第二个字符串对象 |
length | Required. Specify the number of characters from each string to be used in the comparison 必要参数。指定每个字符串中参数比较的字符数量 |
注意点
Note: The strncasecmp() is binary safe and case-insensitive.
注意:strncasecmp()函数是二进制精确的,并且它不区分字母大小写。
Example
案例
代码如下:
输出下面的结果:
echo strncasecmp("Hello world!","hello earth!",6);
?>
The output of the code above will be:
上述代码将
0
内容总结
以上是互联网集市为您收集整理的PHPstrncasecmp字符串比较的小技巧_php技巧全部内容,希望文章能够帮你解决PHPstrncasecmp字符串比较的小技巧_php技巧所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。