Compare two strings using a "natural" algorithm (case-insensitive): in PHP

Description

The following code shows how to compare two strings using a "natural" algorithm (case-insensitive):.

Example


//from   w  w  w . j a  v a  2  s. c  o  m
<?php
    echo strnatcasecmp("2Hello world!","10Hello WORLD!");
    echo "<br>";
    echo strnatcasecmp("10Hello world!","2Hello WORLD!");
?>

The code above generates the following result.





















Home »
  PHP Tutorial »
    Data Types »




Array
Array Associative
Array Util
ArrayObject
Data Types
Date
Date Format
DateTime
Number
String
String Escape
String Filter
String HTML
String Type
Timezone