English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

PHP Basic Tutorial

PHP Advanced Tutorial

PHP & MySQL

PHP Reference Manual

PHP strcasecmp() Function Usage and Example

PHP String Manual

The strcasecmp() function is used to compare two strings (case-insensitive)

Syntax

int strcasecmp ( string $str1 , string $str2 )

Definition and Usage

Used to compare two strings

Note: The strcasecmp() function is binary safe and case-insensitive.

Return value

If str1 is less than str2 Returns < 0; if str1 Greater than str2 Returns > 0; if both are equal, returns 0.

Parameter

NumberParameter and Description
1

str1

Required. The first string

2

str2

Required. The second string

Online Example

Try the following example to compare two strings, case-insensitive, and return the comparison result:

<?php
   //Compare two strings (case-insensitive, Hello and HELlo output the same)
   echo strcasecmp("Hello WORLD!","HELlo PHP!");
    
   echo '<br>';
    $var1 = "Hello";
    $var2 = "heLLO";
    if (strcasecmp($var1, $var2) == 0) {
        echo 'In case-insensitive string comparison, $var1equals $var2';
    }
?>
Test and see‹/›

Output result

7
In case-insensitive string comparison, $var1equals $var2

PHP String Manual