There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
 
Tag Cloud
acer black screen blue screen boot computer connection crash css dell drive driver drivers email error ethernet excel explorer firefox firefox 3 freeze hard drive internet internet explorer itunes laptop linux malware monitor network networking outlook outlook 2003 outlook express password printer problem problems ram router security slow software sound trojan usb virus vista windows windows xp wireless
Web Design & Development
Search
Search in:
 
Advanced Search
Tech Support Guy Forums > Internet & Networking > Web Design & Development >
Solved: Correct Case


HELLO AND WELCOME! Before you can post your question, you'll have to register -- it's completely free! Click here to join today! We highly recommend that you print a copy of our Guide for New Members. Enjoy!

Closed Thread
 
Thread Tools
bob121's Avatar
Senior Member with 188 posts.
 
Join Date: Sep 2006
29-Feb-2008, 03:04 PM #1
Solved: Correct Case
How can you check that the name entered is in the correct case, Because on my game if you enter say james on the game when sending an email and the real username is James, that works fine, but once you go into a if($____ == $_____) command the == Checks if it's exact, It causes problems when people enter the incorrect case, is there a way where it checks the case, and if the case is incorrect it shows an error message.

Thanks James.
tomdkat's Avatar
Computer Specs
Distinguished Member with 3,716 posts.
 
Join Date: May 2006
Location: S.F. Bay Area, CA
Experience: Intermediate
29-Feb-2008, 04:28 PM #2
If you're coding in PHP, the strcasemp() function will be of use to you. You can replace
Code:
if ($var1==$var2)
with
Code:
if (strcasecmp($var1,$var2))
of
Code:
if (strcasecmp($var1,$var2) != 0)
Peace...
bob121's Avatar
Senior Member with 188 posts.
 
Join Date: Sep 2006
01-Mar-2008, 03:28 PM #3
This check only seems to work if they are all different, The usernames are usally mixed case which are causing the problems.

Thanks James.
tomdkat's Avatar
Computer Specs
Distinguished Member with 3,716 posts.
 
Join Date: May 2006
Location: S.F. Bay Area, CA
Experience: Intermediate
01-Mar-2008, 03:43 PM #4
Quote:
Originally Posted by bob121 View Post
This check only seems to work if they are all different, The usernames are usally mixed case which are causing the problems.
Did you try using strcasecmp()? It does exactly what you're looking for.

Here is the sample code from the link I posted above:
Code:
<?php
$var1 = "Hello";
$var2 = "hello";
if (strcasecmp($var1, $var2) == 0) {
    echo '$var1 is equal to $var2 in a case-insensitive string comparison';
}
?>
You can run that code here.

In the sample code above, the only difference between the two strings is the case of 'h'.

I'm not sure I follow what this function does *not* do for you. What am I missing here?

Peace...
bob121's Avatar
Senior Member with 188 posts.
 
Join Date: Sep 2006
01-Mar-2008, 05:14 PM #5
Well that shouldnt work if it what i want ... The H is a different case, I want it to allow no different case's
tomdkat's Avatar
Computer Specs
Distinguished Member with 3,716 posts.
 
Join Date: May 2006
Location: S.F. Bay Area, CA
Experience: Intermediate
01-Mar-2008, 05:43 PM #6
Ok, then you can use the ctype_upper() function to test if a string is all upper case or the ctype_lower() function to test if a string is all lower case.

So, if you want to enforce all lower case values only (for example), you would do something like this:
Code:
if (ctype_lower($var) == False) {
// report an invalid case error of some kind;
}
If you want to enforce a particular character as being upper case or lower case, use the substr() function to get that particular character and then pass that to ctype_upper() or ctype_lower(), something like this:
Code:
$var = "James";
$firstChar = substr($var,0,1);
if (ctype_lower($firstChar) == False) {
// report invalid case detected error of some kind
}
So, what are you wanting to implement as your policy for name's entered in your game? All lower case? All upper case? First character upper case only? Something else?

Peace...
bob121's Avatar
Senior Member with 188 posts.
 
Join Date: Sep 2006
02-Mar-2008, 03:33 AM #7
I've made something which does exactly what i want it too

Code:
$user=$_POST['username'];
if($user){
$checkinit2 = mysql_fetch_object(mysql_query("SELECT * FROM users WHERE username='$user'"));
$user2 = $checkinit2->username;
if($user !== $user2){
echo" Incorrect Case ";
}else{
echo" Correct Case ";
}

}
Thanks All You're Help !
tomdkat's Avatar
Computer Specs
Distinguished Member with 3,716 posts.
 
Join Date: May 2006
Location: S.F. Bay Area, CA
Experience: Intermediate
02-Mar-2008, 10:28 AM #8
Great! Glad you got it sorted out.

Peace...
Closed Thread

THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who help people like you solve computer problems. See our Welcome Guide to get started.



Thread Tools


You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 08:49 PM.
Copyright © 1996 - 2008 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Powered by Cermak Technologies, Inc.