只是这样就需要转换两次。大多时候,我们是针对字符集转换的时候才会这样,比如判断参数传进来是否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 的时候,就是这样判断的。我也因此学到了一招。
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
必要参数。指定每个字符串中参数比较的字符数量Tips and Notes
注意点
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
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)
必要参数。指定参与比较的第一个字符串对象 string2 Required. Specifies the second string to compare
必要参数。指定参与比较的第二个字符串对象 length Required. Specify the number of characters from each string to be used in the comparison
必要参数。指定每个字符串中参数比较的字符数量Tips and Notes
注意点
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
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件!
如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
金钱帮资源网 Copyright www.kbjia.com
暂无“PHP strncasecmp字符串比较的小技巧”评论...
更新日志
2024年10月21日
2024年10月21日
- 群星2013-青春缤纷辑压箱宝大公开3CD2[新加坡限量版][WAV整轨]
- 林育群.2013-BalladShow(日本版)【环球】【WAV+CUE】
- 陈加洛.1992-痛到感觉不到【宝丽金】【WAV+CUE】
- 群星.2023-宿命之敌电视剧原声带【韶愔音乐】【FLAC分轨】
- 東京事変-大発見[FLAC+CUE]
- 椎名林檎-三文ゴシップ[FLAC+CUE]
- 2024年08月04日
- 裘德《裘德「最后的水族馆」演唱会LIVE》[320K/MP3][228.89MB]
- 裘德《裘德「最后的水族馆」演唱会LIVE》[24bit 48kHz][FLAC/分轨][2.08G]
- 基因三重奏《如果你什么都不说 音乐会现场录音》[320K/MP3][145.37MB]
- 孟庭苇.1996-月亮说话(2020环球24KGOLD限量版)【上华】【WAV+CUE】
- 群星.1997-新艺宝优质音响系列·国语精选监听版【新艺宝】【WAV+CUE】
- 阿桑.2005-寂寞在唱歌(星外星引进版)【华研国际】【WAV+CUE】
- 基因三重奏《如果你什么都不说 音乐会现场录音》[FLAC/分轨][287.43MB]
- 蔡题谦《我爱你,却依然要看你走》[320K/MP3][88.65MB]