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
  • Calculate the edit distance between two strings levenshtein

    levenshtein

    Calculatetheeditdist
  • Calculate a string of crc32 polynomials crc32

    crc32

    Calculateastringofcr
  • Find the first occurrence of a string strstr

    strstr

    Findthefirstoccurren
  • Set the first character of the string to lowercase lcfirst

    lcfirst

    Setthefirstcharacter
  • Returns the formatted string sprintf

    sprintf

    Returnstheformatteds
  • Insert HTML newline tag before all new lines of a string nl2br

    nl2br

    InsertHTMLnewlinetag
  • Use one string to split another string into an array explode

    explode

    Useonestringtosplita
  • Split the string into smaller chunks chunk_split

    chunk_split

    Splitthestringintosm
Popular Articles