文字

strcoll

(PHP 4 >= 4.0.5, PHP 5)

strcoll基于区域设置的字符串比较

说明

int strcoll ( string $str1 , string $str2 )

注意该比较区分大小写。和 strcmp() 不同,该函数不是二进制安全的。

strcoll() 使用当前区域设置进行比较。如果当前区域为 C 或 POSIX,该函数等同于 strcmp()

参数

str1

第一个字符串。

str2

第二个字符串。

返回值

如果 str1 小于 str2 返回 < 0; 如果 str1 大于 str2 返回 > 0;如果两者相等,返回 0。

更新日志

版本 说明
4.2.3 函数在 Win32 平台可用。

参见

  • preg_match() - 执行一个正则表达式匹配
  • strcmp() - 二进制安全字符串比较
  • strcasecmp() - 二进制安全比较字符串(不区分大小写)
  • substr() - 返回字符串的子串
  • stristr() - strstr 函数的忽略大小写版本
  • strncasecmp() - 二进制安全比较字符串开头的若干个字符(不区分大小写)
  • strncmp() - 二进制安全比较字符串开头的若干个字符
  • strstr() - 查找字符串的首次出现
  • setlocale() - 设置地区信息

用户评论:

[#1] sakkarinlaohawisut15 at hotmail dot com [2003-03-22 11:31:14]

[#2] [2002-08-27 07:05:54]

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!

上一篇: 下一篇: