case sensitivity?

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
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

case sensitivity?

Post by d3ad1ysp0rk »

I know theres a way, but I've never been good at finding things in the php manuel.. :oops:

Is there a way to make something non case sensitive, ie:

Code: Select all

<?php
if($user=="Josh")
{
echo "Hi Josh.";
}

?>
still works whether $user is "Josh" or "joSH"

Thanks in advance.
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

Code: Select all

if(!strcmp(strtolower($user), strtolower('Josh')){
echo 'Hi, Josh.';
User avatar
Kriek
Forum Contributor
Posts: 238
Joined: Wed May 29, 2002 3:46 am
Location: Florida
Contact:

Post by Kriek »

LiLpunkSkateR wrote:non case sensitive
You mean case-insensitive.

Code: Select all

<?php
    if(stristr($user, 'Josh')) &#123;
        echo 'Hi Josh';
    &#125;
?>
See -> the stristr() function.
User avatar
devork
Forum Contributor
Posts: 213
Joined: Fri Aug 08, 2003 6:44 am
Location: p(h) developer's network

Post by devork »

also
if($user=='Josh') has difference with if ($user=="josh")
Cruzado_Mainfrm
Forum Contributor
Posts: 346
Joined: Sun Jun 15, 2003 11:22 pm
Location: Miami, FL

Post by Cruzado_Mainfrm »

try POSIX regex function

Code: Select all

<?php
$inputname = "John";
$storedname = "john";
if (eregi("^".$inputname."$",$storedname)) {
    echo "Input name matches stored one.";
} else {
    echo "Input name mismatches stored one.";
}
?>
User avatar
DuFF
Forum Contributor
Posts: 495
Joined: Tue Jun 24, 2003 7:49 pm
Location: USA

Post by DuFF »

Heres what I do:
  • Make the username string lowercase (database name is also lowercase)
    Compare the username string to the database name
    Store the inputted username in a session
    Output the session data, which is saved how they spelt it.
Post Reply