O'Reilly logo

Core PHP Programming, Third Edition by Leon Atkinson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

12.2. String Comparison

These functions compare one string to another. They all return integers. A negative integer means the first string comes before the second. Zero means the strings are equal. A positive number means the first string comes after the second. You may consider the hashing functions described later in this function for comparing strings.

integer strcasecmp(string first, string second)

The strcasecmp function (Listing 12.17) operates identically to strcmp except that it treats uppercase and lowercase as identical.

Listing 12.17. strcasecmp
<?php
    $first = "abc";
    $second = "aBc";

    if(strcasecmp($first, $second) == 0)
    {
        print("strings are equal");
    }

    else
    {
        print("strings are not equal");
    }
?>

integer strcmp(string first, string ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required