case insensitive string comparison

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
davidklonski
Forum Contributor
Posts: 128
Joined: Mon Mar 22, 2004 4:55 pm

case insensitive string comparison

Post by davidklonski »

Hello

I need to compare string in a locale-aware manner.
I was using strcoll.

However, I need a case insensitive string comparison.
Does anyone know of a way to achieve that?
I cannot use strcasecmp because it is not locale-aware.

thanks in advance.
Grim...
DevNet Resident
Posts: 1445
Joined: Tue May 18, 2004 5:32 am
Location: London, UK

Post by Grim... »

Convert both strings to lowercase first using [php_man]strtolower[/php_man]?
User avatar
Joe
Forum Regular
Posts: 939
Joined: Sun Feb 29, 2004 1:26 pm
Location: UK - Glasgow

Post by Joe »

Code: Select all

$string1 = "HELLO";
$string2 = "hello";

$string1 = strtolower($string1);

if ($string1 == $string2)
 True;
else
 False;
User avatar
Joe
Forum Regular
Posts: 939
Joined: Sun Feb 29, 2004 1:26 pm
Location: UK - Glasgow

Post by Joe »

^_^ Just a little example, hehe
User avatar
Bill H
DevNet Resident
Posts: 1136
Joined: Sat Jun 01, 2002 10:16 am
Location: San Diego CA
Contact:

Post by Bill H »

Or strcasecmp(str1, str2);
Post Reply