Current Location: Home> Function Categories> strncasecmp

strncasecmp

Binary safe comparison of several characters at the beginning of a string (case insensitive)
Name:strncasecmp
Category:String
Programming Language:php
One-line Description:Comparison of strings for the first n characters (case insensitive).

Definition and usage

strncasecmp() function compares two strings.

Note: strncasecmp() is binary-safe and is not case sensitive.

Tip: This function is similar to strcasecmp() function. The difference is that strcasecmp() does not have a length parameter.

Example

Example 1

Compare two strings (case insensitive):

 <?php
echo strncasecmp ( "I love China!" , "I love Shanghai!" , 6 ) ;
?>

Try it yourself

Example 2

Compare two strings (case insensitive, China and CHINA output the same):

 <?php
echo strncasecmp ( "China" , "China" , 6 ) ;
echo "<br>" ;
echo strncasecmp ( "China" , "CHINA" , 6 ) ;
?>

Try it yourself

grammar

 strncasecmp ( string1 ,
string2 , length )
parameter describe
string1 Required. Specifies the first string to be compared.
string2 Required. Specifies the second string to be compared.
length Required. Specifies the number of characters each string uses for comparison.
Similar Functions
  • Write the formatted string to the stream fprintf

    fprintf

    Writetheformattedstr
  • Binary safe string comparison strcmp

    strcmp

    Binarysafestringcomp
  • Inversely escape an escaped string stripslashes

    stripslashes

    Inverselyescapeanesc
  • Calculate the md5 hash value of a given file md5_file

    md5_file

    Calculatethemd5hashv
  • Use another string to fill a string to a length str_pad

    str_pad

    Useanotherstringtofi
  • Alias ​​of strstr strchr

    strchr

    Alias​​ofstrstr
  • Remove spaces (or other characters) from the beginning and end of the string trim

    trim

    Removespaces(orother
  • Calculate the edit distance between two strings levenshtein

    levenshtein

    Calculatetheeditdist
Popular Articles