strcoll – PHP String Functions

Syntax :

strcoll ( string1, string2 );

Description :

strcoll() function will function compares two strings based on locale and  this comparison is case sensitive.

Note : If the current locale is C or POSIX, this function is equivalent to strcmp().

Parameter :

  • string1 – This is a Required parameter. It is the first string which will be compared.
  • string2 – This is a Required parameter. It is the second string which will be compared.

Output :

It will returns below values are:

  • 0 – if the two strings are equal.
  • < 0 – if string1 is less than string2.
  • > 0 – if string1 is greater than string2.

ChangeLog :

[table caption=”” width=”100%” colwidth=”25%|75%” colalign=”left|left”]
Version, Description
PHP 4.2.3 , This function now works on win32.
[/table]


Related articles : preg_match(), strcmp(), strcasecmp(), substr(), stristr(), strncasecmp(), strstr(), strncmp().


strcoll() – PHP Functions Example 1 : It returns 0 if the strings are equal.
<?php
$str1 = 'Tutorialmines';
$str2 = 'Tutorialmines';

setlocale (LC_COLLATE, 'NL');
echo strcoll($str1,$str2);
echo "<br>";

setlocale (LC_COLLATE, 'en_US');
echo strcoll($str1,$str2);
echo "<br>";

setlocale (LC_COLLATE, 'de_DE');
echo strcoll($str1,$str2);
?>

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *