How to compare strings in php regardless of size
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:
- ##string1 Required. Specifies the first string to compare.
- #string2 Required. Specifies the second string to be compared.
- #length Required. Specifies the number of characters per string used for comparison.
- 0 - If the two strings are equal
- >0 - If string1 is greater than string2
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!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

Notepad++7.3.1
Easy-to-use and free code editor

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

SublimeText3 Mac version
God-level code editing software (SublimeText3)

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment
