Home >Backend Development >PHP Tutorial >strncmp() function in PHP
strncmp() function is used to compare the first n characters.
Note - This function is case sensitive.
strncmp(str1, str2, len)
##str1 − The first string
str2 − The second string
len − The number of characters used for comparison.
<?php echo strncmp("Demo text!","DEMO word!",4); ?>OutputThe following is the output−
8192Example Let’s see another example − Real time demonstration
<?php $str1 = "TomHanks"; $str2 = "tomhanks"; print_r(strncmp($str1, $str2, 8)); ?>OutputThe following is the output−
-32
The above is the detailed content of strncmp() function in PHP. For more information, please follow other related articles on the PHP Chinese website!