English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
PHP String Manual of String Functions
The strncasecmp() function is used for binary safe comparison of the first few characters of the string (case-insensitive).
strncasecmp(string1,string2,length)
It is used to compare two strings (case-insensitive).
Note:strncasecmp() is binary safe and case-insensitive.
Tip:The function is similar tostrcasecmp() The function is similar, but the difference is that strcasecmp() does not have a length parameter, while for the strncasecmp() function, you can specify the length (i.e., maximum comparison length) of the two strings to be compared.
If String1 Less than String2 Return < 0; if String1 Greater than String2 Return > 0; if they are equal, return 0.
Serial Number | Parameters and Description |
---|---|
1 | String1 First String |
2 | String2 Second String |
3 | Length Maximum Comparison Length |
Try the following example, compare two strings (case-insensitive, 'PHP' and 'Php' output is the same)
<?php //Case-insensitive comparison, 'PHP' and 'Php' output is the same echo strncasecmp("Hello PHP","Hello PHP",9); echo "<br>"; //Case-insensitive comparison, 'hello' and 'hELLo' output is the same echo strncasecmp("hello PHP","hELLo PHP",9); ?>Test and see‹/›
Output Result
0 0