Home  >  Article  >  Backend Development  >  How to compare strings in php without case sensitivity

How to compare strings in php without case sensitivity

王林
王林Original
2020-08-20 15:50:523015browse

How to compare strings in PHP without case sensitivity: You can use the built-in function strncasecmp() to compare. If the function returns 0, it means the two strings are equal. If the return value is less than 0, it means string1 is less than string2.

How to compare strings in php without case sensitivity

strncasecmp() function compares two strings (not case sensitive).

(Recommended tutorial: php graphic tutorial)

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.

Return value:

  • 0 - If the two strings are equal

  • b29410e8f8c47be4d477a5f851868b370 - If string1 is greater than string2

(Learning video recommendation: php video tutorial)

Example:

<?php
echo strncasecmp("Hello","Hello",6);
echo "<br>";
echo strncasecmp("Hello","hELLo",6);
?>

Output:

0
0

The above is the detailed content of How to compare strings in php without case sensitivity. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn