Monday, 29 September 2014

strcoll in PHP

PHP strcoll() function is utilized to compare two strings.This function utilizes current locale for doing the comparison. If the current locale is C or POSIX, Strcoll function is equivalent to strcmp().

The function returns :

0 – if the two strings are exactly equivalent.
<0 – if smaller byte is found in the string1.
>0 –if smaller byte is found in the string2.
Syntax:

strcoll(string1,string2)
string1 : Required. Specifies the first string.

string2 : Required. Specifies the second string.

Note : The PHP strcoll() function is case-sensitive but not binary safe. 

Example:

<?php 
setlocale (LC_COLLATE, 'NL');
echo strcoll("Good Morning","Good MORNING");
echo "<br />"; 
setlocale (LC_COLLATE, 'en_US'); 
echo strcoll("Good Morning","Good MORNING");
 ?>
Output will be:
-1 
1

0 comments:

Post a Comment