Graphic Design Forum and Web Design Forum  

Go Back   Graphic Design Forum and Web Design Forum »Web Design Forum »Programming Forum

Notices

Programming Forum Web and Software Programming Forum - Java, PHP, SQL etc.


Reply
 
LinkBack (1) Thread Tools Display Modes
  1 links from elsewhere to this Post. Click to view. #1 (permalink)  
Old 03-09-2007, 06:28 PM
PR Design's Avatar
CSS Wizardry
 
Join Date: May 2007
Location: Yorkshire, England
Gender: Male
Posts: 3,350
Default PHP help please

I thought I'd call upon the minds of the web's best for my little problem. Basically I'm really really new to PHP and I'm using this little book among other things. I'm on a tutorial about the switch statement with this code:

Code:
switch ($name) {
     case "Damon":
     case "Shelley":
          echo "Welcome, $name, you are my friend.";
          break;
     case "Adolf":
     case "Saddam":
          echo "You are no friend of mine, $name.";
          break;
     default:
          echo "I don't know you, $name";
}
The problem is that if someone types damon or any other name in lowercase they get the default message. I could easily type both variations but when the list gets quite long it's going to be a nightmare!
Is there a snippet or script which will make the case irrelevant?
Digg this Post!Add Post to del.icio.usBookmark Post in Technorati Share This Article & VoteReddit! Wong this Post!Stumble this Post!RSS Share on FacebookForum Netvibes Page
Reply With Quote
  #2 (permalink)  
Old 03-09-2007, 06:40 PM
LeadMagnet's Avatar
Mr. Tambourine Man
 
Join Date: Jun 2007
Location: Ireland
Gender: Male
Posts: 1,381
Default

create a variable $name_lower from $name and use strtolower to convert it to lowercase.
Use $name_lower in your switch but echo $name in the response.
__________________
Subtlety is my middle name... and first and last in case you didn't get the point.
Digg this Post!Add Post to del.icio.usBookmark Post in Technorati Share This Article & VoteReddit! Wong this Post!Stumble this Post!RSS Share on FacebookForum Netvibes Page
Reply With Quote
  #3 (permalink)  
Old 03-09-2007, 06:44 PM
PR Design's Avatar
CSS Wizardry
 
Join Date: May 2007
Location: Yorkshire, England
Gender: Male
Posts: 3,350
Default

As easy as that?! Nice one thank you!
Digg this Post!Add Post to del.icio.usBookmark Post in Technorati Share This Article & VoteReddit! Wong this Post!Stumble this Post!RSS Share on FacebookForum Netvibes Page
Reply With Quote
  #4 (permalink)  
Old 19-11-2007, 07:07 PM
jontywagener's Avatar
Experienced Member
 
Join Date: Oct 2007
Location: South Africa
Posts: 126
Default

hmmmm
Digg this Post!Add Post to del.icio.usBookmark Post in Technorati Share This Article & VoteReddit! Wong this Post!Stumble this Post!RSS Share on FacebookForum Netvibes Page
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 09:55 PM.



Estetica Design Forum's Privacy Policy
Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0 RC5