Current Location: Home> Function Categories> strcasecmp

strcasecmp

Binary safe case-insensitive string comparison
Name:strcasecmp
Category:String
Programming Language:php
One-line Description:Compare two strings (case insensitive).

Definition and usage

strcasecmp() function compares two strings.

Tip: The strcasecmp() function is binary-safe and is case-insensitive.

Tip: This function is similar to the strncasecmp() function, except that with strncasecmp() you can specify the number of characters each string is used for comparison.

Example

Example 1

Compare two strings (case insensitive):

 <?php
echo strcasecmp ( "shanghai" , "SHANGHAI" ) ;
?>

Try it yourself

Example 2

Comparison of two strings (case insensitive, HELLO and hELLo outputs are the same):

 <?php
echo strcasecmp ( "Shanghai" , "SHANGHAI" ) ;
echo "<br>" ;
echo strcasecmp ( "Shanghai" , "sHANGHai" ) ;
?>

Try it yourself

Example 3

Different return values:

 <?php
echo strcasecmp ( "Hello world!" , "HELLO WORLD!" ) ; // Two strings are equal
echo strcasecmp ( "Hello world!" , "HELLO" ) ; // string1 is greater than string2
echo strcasecmp ( "Hello world!" , "HELLO WORLD! HELLO!" ) ; // string1 is less than string2
?>

Try it yourself

grammar

 strcasecmp ( string1 , string2 )
parameter describe
string1 Required. Specifies the first string to be compared.
string2 Required. Specifies the second string to be compared.
Similar Functions
Popular Articles