Page 1 of 1

case sensitivity?

Posted: Tue Oct 21, 2003 9:28 pm
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.

Posted: Tue Oct 21, 2003 9:37 pm
by markl999

Code: Select all

if(!strcmp(strtolower($user), strtolower('Josh')){
echo 'Hi, Josh.';

Posted: Wed Oct 22, 2003 12:44 am
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.

Posted: Wed Oct 22, 2003 2:22 am
by devork
also
if($user=='Josh') has difference with if ($user=="josh")

Posted: Wed Oct 22, 2003 4:16 pm
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.";
}
?>

Posted: Wed Oct 22, 2003 5:49 pm
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.