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 ...

Get Core PHP Programming, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.