Simple Case insensitive question

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
sixseven67
Forum Newbie
Posts: 3
Joined: Thu Oct 22, 2009 4:45 pm

Simple Case insensitive question

Post by sixseven67 »

I've researched and tried a number of things but can't figure this one out. When this if statement receives 'gallery' from the url I don't want it to be case sensitive. Currently a person would have to type the name exactly as I have it below in order for the correct image to show.

I've tried playing around with the i modifier but it's not coming together. Any help would be great. Thanks.

Code: Select all

 
elseif($_GET['gallery']=="arte x arte")
{
   $userImage = "arte_x_arte.jpg";
}
 
Reviresco
Forum Contributor
Posts: 172
Joined: Tue Feb 19, 2008 4:18 pm
Location: Milwaukee

Re: Simple Case insensitive question

Post by Reviresco »

Convert gallery and the image names to lower case using strtolower() when you compare them:

http://php.net/manual/en/function.strtolower.php
User avatar
Mirge
Forum Contributor
Posts: 298
Joined: Thu Sep 03, 2009 11:39 pm

Re: Simple Case insensitive question

Post by Mirge »

sixseven67 wrote:I've researched and tried a number of things but can't figure this one out. When this if statement receives 'gallery' from the url I don't want it to be case sensitive. Currently a person would have to type the name exactly as I have it below in order for the correct image to show.

I've tried playing around with the i modifier but it's not coming together. Any help would be great. Thanks.

Code: Select all

 
elseif($_GET['gallery']=="arte x arte")
{
   $userImage = "arte_x_arte.jpg";
}
 
In addition to using strtolower(), if you're wanting to replace spaces with underscores, you should also look at http://www.php.net/str_replace/.
Post Reply