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

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • VCS
  • Interview Questions
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • 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. PHP atanh function – Inverse hyperbolic tangent
  2. PHP Function str_split() – Convert a string to an array
  3. PHP cos function – Cosine
  4. PHP decbin function – Decimal to binary
  5. PHP function convert_cyr_string() – Convert from one Cyrillic character set to another
  6. PHP function chunk_split() – Split a string into smaller chunks
  7. PHP asin function – Arc sine
  8. PHP bindec function – Convert a number between arbitrary bases
  9. PHP function str_ireplace() – Case-insensitive version of str_replace()
  10. PHP function abs – Absolute value

You May Also Like

Primary Sidebar

Recent Posts

  • qsub Command Examples in Linux
  • qsub: command not found
  • qrcp Command Examples in Linux
  • qmrestore Command Examples in Linux

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright