Jump to content

[SOLVED] Simple Case insensitive question


sixseven

Recommended Posts

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.

 

if($_GET['gallery']=="arte x arte")
{
   $userImage = "arte_x_arte.jpg";
}

Link to comment
https://forums.phpfreaks.com/topic/179379-solved-simple-case-insensitive-question/
Share on other sites

Hi sixseven,

 

You could use PHP's array_change_key_case() to do this.

 

Change your code to read:

 

$lcget = array_change_key_case($_GET);
$gallery = $lcget['gallery'];

if($gallery=="arte x arte")
{
   $userImage = "arte_x_arte.jpg";
}

 

The above is useful if you have other $_GET requests you wish to make lowercase, as it will convert the entire $_GET array.

 

Or you could just use PHP's strtolower() function to perform a conversion on the single $_GET using:

 

$gallery = $_GET['gallery'];
if(strtolower($gallery)=="arte x arte")
{
   $userImage = "arte_x_arte.jpg";
}

 

Hope this helps.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.