strcoll 


string apg

COMPARES two STRINGS by the case-sensitive way using the current LOCALE for doing it.





If $str1 is less than $str2 this function retuns an integer less than ZERO.

If $str1 is equal to $str2 this function returns ZERO.

If $str1 is greater than $str2 this function returns an an integer greater than ZERO.


This function is binary-safe


This function uses the current LOCALE for doing the comparisons.

If the current LOCALE is C or POSIX, this function is equivalent to strcmp.



<?php

int strcoll 
str $str1 str $str2 )


where,

$str1 The first STRING to compare 

$str2 
The second STRING to compare 

?>
 

$str1


The first STRING to be compared.



$str2


The second STRING to be compared.



LOCALES


LOCALEs are organized and identified according to RFC 5646.

Not all PHP functions are compatible with LOCALE.

Whenever possible, this will be considered.

CONSTANTS USES
LC_ALL FOR ALL VARIABLES
LC_COLLATE Comparisons with STRINGS
See, strcoll
LC_CTYPE Conversion and Classification of Characters
See, strtoupper
LC_MONETARY Monetary Standards
See, localeconv
LC_NUMERIC Decimal Separator
See, localeconv
LC_TIME Date and Time Formatting with strftime
LC_MESSAGES System Responses
Available if PHP was compiled with libintl
ed48

On Windows,  setlocale(LC_ALL, '')  sets the locale names from the system's regional/language settings, (accessible via Control Panel).

The return value of setlocale depends on the system that PHP is running.

It returns exactly what the system setlocale function returns.

Since PHP 7.0.0 only  LC_*  constants can be used as of this version, because the support for the category parameter passed as a STRING has been removed.



  1 EXERCISE   

<?php

setlocale
(LC_COLLATE'C');

function 
str_coll1 ($par1$par2

    
$stcmp12 strcoll($par1$par2); 
     
if (
$stcmp12 0

echo 
'Returned value: ' $stcmp12 
'<br>therefore,<br>' $par1 
'<br>is GREATER than<br>' $par2 '<br><br>'

elseif (
$stcmp12 0

echo 
'Returned value: ' $stcmp12 
'<br>therefore,<br>' $par1 
'<br>is LESS than<br>' $par2 '<br><br>'

else 

echo 
'Returned value: ' $stcmp12 
'<br>therefore,<br>' $par1 
'<br>is EQUAL to<br>' $par2 '<br><br>'



$srcm01 'Augusta'

$srcm02 'AUGUSTA'

$srcm03 'angusta'

$srcm04 'angusta'


str_coll1($srcm01$srcm02); 

str_coll1($srcm01$srcm03); 

str_coll1($srcm03$srcm01); 

str_coll1($srcm03$srcm04); 

?> 

  2 EXERCISE   

<?php

setlocale 
(LC_ALL'pt_PT''ptg''portuguese');

$srcm01 "abcdefàáãç";

$srcm02 "abcdefàá";

function 
str_coll12 ($par1$par2

    
$stcmp12 strcoll($par1$par2); 
     
if (
$stcmp12 0

echo 
'Returned value: ' $stcmp12 
'<br>therefore,<br>' $par1 
'<br>is GREATER than<br>' $par2 '<br><br>'

elseif (
$stcmp12 0

echo 
'Returned value: ' $stcmp12 
'<br>therefore,<br>' $par1 
'<br>is LESS than<br>' $par2 '<br><br>'

else 

echo 
'Returned value: ' $stcmp12 
'<br>therefore,<br>' $par1 
'<br>is EQUAL to<br>' $par2 '<br><br>'

}  

str_coll12($srcm01$srcm02);

echo 
'or<br><br>'

str_coll12($srcm02$srcm01); 

?>

  3 EXERCISE   

<?php

setlocale 
(LC_ALL'');

$srcm01 "SÃO PAULO";;

$srcm02 "São Paulo";

function 
str_coll13 ($par1$par2

    
$stcmp12 strcoll($par1$par2); 
     
if (
$stcmp12 0

echo 
'Returned value: ' $stcmp12 
'<br>therefore,<br>' $par1 
'<br>is GREATER than<br>' $par2 '<br><br>'

elseif (
$stcmp12 0

echo 
'Returned value: ' $stcmp12 
'<br>therefore,<br>' $par1 
'<br>is LESS than<br>' $par2 '<br><br>'

else 

echo 
'Returned value: ' $stcmp12 
'<br>therefore,<br>' $par1 
'<br>is EQUAL to<br>' $par2 '<br><br>'

}  

str_coll13($srcm01$srcm02);

echo 
'or<br><br>'

str_coll13($srcm02$srcm01); 

?>

  4 EXERCISE   

<?php

setlocale 
(LC_ALL'en_US');

$srcm01 'Many hands make light work.';

$srcm02 'MANY HANDS MAKE LIGHT WORK.';

function 
str_coll14 ($par1$par2

    
$stcmp12 strcoll($par1$par2); 
     
if (
$stcmp12 0

echo 
'Returned value: ' $stcmp12 
'<br>therefore,<br>' $par1 
'<br>is GREATER than<br>' $par2 '<br><br>'

elseif (
$stcmp12 0

echo 
'Returned value: ' $stcmp12 
'<br>therefore,<br>' $par1 
'<br>is LESS than<br>' $par2 '<br><br>'

else 

echo 
'Returned value: ' $stcmp12 
'<br>therefore,<br>' $par1 
'<br>is EQUAL to<br>' $par2 '<br><br>'

}  

str_coll14($srcm01$srcm02);

echo 
'or<br><br>'

str_coll14($srcm02$srcm01); 

?>

  5 EXERCISE   

<?php

 $a 
'a';
 
$b 'A';

setlocale (LC_COLLATE'C');

$result strcoll($a$b);

if(
$result 0) {
    echo 
"Pass\n";
}

?>