• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • VCS
  • Interview Questions
  • Database
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

PHP function strcasecmp() – Binary safe case-insensitive string comparison

by admin

The strcasecmp() function is used to compare two case-sensitive strings. This is a case-insensitive version of the strcmp(). This function was introduced in PHP3. The function returns a number less than 0 if one is less than two, 0 if the two strings are equal, and a number greater than 0 if one is greater than two. The comparison is case-insensitive—that is, “Alphabet” and “alphabet” are considered equal.

Syntax:

strcasecmp(string $string1, string $string2): int

Consider the example shown below:

$result = strcasecmp("Hello", "hello");

That will return 0, because PHP will ignore the case difference. Using strcmp() instead would have returned -1: “Hello” would come before “hello”.

Parameters

Parameter Description
string1 The first string
string2 The second string

Return Values

Returns < 0 if string1 is less than string2; > 0 if string1 is greater than string2, and 0 if they are equal.

Examples

Example 1:

<?php
$text1 = “Good morning”;
$text2 = “Good morning”;
if (strcasecmp($text1, $text2) == 0) {
echo ‘$text1 is equal to $text2 in a case-insen-
sitive string comparison’; }
?>

The output of the above program is as follows:

$text1 is equal to $text2 in a case-insensitive string comparison

Filed Under: PHP

Some more articles you might also be interested in …

  1. htaccess Cheatsheet
  2. PHP function abs – Absolute value
  3. PHP connection_status function – Returns connection status bitfield
  4. PHP function chr() – Generate a single-byte string from a number
  5. PHP function chunk_split() – Split a string into smaller chunks
  6. PHP asin function – Arc sine
  7. PHP atan2 function – Arc tangent of two variables
  8. PHP decbin function – Decimal to binary
  9. PHP function stripcslashes() – Un-quote string quoted with addcslashes()
  10. PHP function str_repeat() – Repeat a string

You May Also Like

Primary Sidebar

Recent Posts

  • Vanilla OS 2 Released: A New Era for Linux Enthusiasts
  • mk Command Examples
  • mixxx Command Examples
  • mix Command Examples

© 2025 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright