strcoll() - 基于区域设置的字符串比较 - php 字符串函数
strcoll()
(PHP 4 >= 4.0.5, PHP 5, PHP 7)
基于区域设置的字符串比较
说明
strcoll(string$str1,string$str2): int注意该比较区分大小写。和 strcmp()不同,该函数不是二进制安全的。
strcoll()使用当前区域设置进行比较。如果当前区域为 C 或 POSIX,该函数等同于 strcmp()。
参数
$str1:第一个字符串。
$str2:第二个字符串。
返回值
如果$str1小于$str2返回 0;如果两者相等,返回 0。
更新日志
版本 | 说明 |
---|---|
4.2.3 | 函数在 Win32 平台可用。 |
参见
preg_match()
执行匹配正则表达式strcmp()
二进制安全字符串比较strcasecmp()
二进制安全比较字符串(不区分大小写)substr()
返回字符串的子串stristr()
strstr 函数的忽略大小写版本strncasecmp()
二进制安全比较字符串开头的若干个字符(不区分大小写)strncmp()
二进制安全比较字符串开头的若干个字符strstr()
查找字符串的首次出现setlocale()
设置地区信息
Note that some platforms implement strcmp() and strcasecmp() according to the current locale when strings are not binary equal, so that strcmp() and strcoll() will return the same value! This depends on how the PHP strcmp() function is compiled (i.e. if it uses the platform specific strcmp() found in its standard library!). In that case, the only difference between strcoll() and strcmp() is that strcoll() may return 0 for distinct strings(i.e. consider strings are equal) while strcmp() will differentiate them if they have distinct binary encoding! This typically occurs on Asian systems. What you can be sure is that strcmp() will always differentiate strings that are encoded differently, but the relative order may still use the current locale setting for collation order!
You should not rely on this function to properly compare localized strings. Using the Collator (from the intl module) you will get the expected result for e.g. sorting such that the string "Österreich" will rank higher than "Zeta", but after "Oesterreich". strcoll's output will differ per platform, locale and used c library, while the Collator will give more stable results on different platforms.
strcoll()'s behavior is sometimes a little bit confusing. It depends on LC_COLLATE in your locale. This is useful e. g. if want to sort an array by using strcoll: This is like sort($a): Array ( [0] => A [1] => B [2] => a [3] => b [4] => � [5] => � ) This is completely different: Array ( [0] => a [1] => A [2] => � [3] => � [4] => b [5] => B )
鹏仔微信 15129739599 鹏仔QQ344225443 鹏仔前端 pjxi.com 共享博客 sharedbk.com
免责声明:我们致力于保护作者版权,注重分享,当前被刊用文章因无法核实真实出处,未能及时与作者取得联系,或有版权异议的,请联系管理员,我们会立即处理! 部分文章是来自自研大数据AI进行生成,内容摘自(百度百科,百度知道,头条百科,中国民法典,刑法,牛津词典,新华词典,汉语词典,国家院校,科普平台)等数据,内容仅供学习参考,不准确地方联系删除处理!邮箱:344225443@qq.com)
图片声明:本站部分配图来自网络。本站只作为美观性配图使用,无任何非法侵犯第三方意图,一切解释权归图片著作权方,本站不承担任何责任。如有恶意碰瓷者,必当奉陪到底严惩不贷!
内容声明:本文中引用的各种信息及资料(包括但不限于文字、数据、图表及超链接等)均来源于该信息及资料的相关主体(包括但不限于公司、媒体、协会等机构)的官方网站或公开发表的信息。部分内容参考包括:(百度百科,百度知道,头条百科,中国民法典,刑法,牛津词典,新华词典,汉语词典,国家院校,科普平台)等数据,内容仅供参考使用,不准确地方联系删除处理!本站为非盈利性质站点,本着为中国教育事业出一份力,发布内容不收取任何费用也不接任何广告!)