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)
| 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
案例
复制代码 代码如下:
<?php
echo strncasecmp("hello world!","hello earth!",6);
?>
the output of the code above will be:
上述代码将输出下面的结果:
0
【说明】:本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:)!