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
  • Convert the first letter of each word in the string to uppercase ucwords

    ucwords

    Convertthefirstlette
  • Convert the first byte of the string to a value between 0-255 ord

    ord

    Convertthefirstbyteo
  • Return information about the words used in the string str_word_count

    str_word_count

    Returninformationabo
  • Case-insensitive strstr stristr

    stristr

    Case-insensitivestrs
  • Calculate the sha1 hash value of a string sha1

    sha1

    Calculatethesha1hash
  • Convert logical-Hebrew to visual-Hebrew and convert newlines hebrevc

    hebrevc

    Convertlogical-Hebre
  • Query language and locale information nl_langinfo

    nl_langinfo

    Querylanguageandloca
  • Write the formatted string to the stream fprintf

    fprintf

    Writetheformattedstr
Popular Articles