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
Popular Articles