In PHP, you can use the built-in function strncasecmp() to compare strings without case sensitivity, the syntax is "strncasecmp(str1,str2,length)". If the return value is 0, it means that the two strings are equal; if the return value is less than 0, it means that str1 is less than str2.
The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
php case-insensitive comparison String
<?php echo strncasecmp("Hello","Hello",6); echo "<br>"; echo strncasecmp("Hello","hELLo",6); ?>
Output:
0 0
Because the strncasecmp() function is not case-sensitive, the output of Hello and hELLo is the same.
[Recommended learning: "PHP Video Tutorial"]
Related function introduction:
strncasecmp() Function is used to compare two strings (case insensitive).
Syntax:
strncasecmp(string1,string2,length)
Parameters:
Programming video! !
The above is the detailed content of How to compare strings in php regardless of size. For more information, please follow other related articles on the PHP Chinese website!