in_array() - case insensitive

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
JKM
Forum Contributor
Posts: 221
Joined: Tue Jun 17, 2008 8:12 pm

in_array() - case insensitive

Post by JKM »

Hi there,

Code: Select all

$array = array('jpg', 'gif');
$extension = explode('.', $_FILES['file']['name']);
$extension = $extension[count($extension)-1];
$continue = in_array($array, $extension) ? true : false;
Is it possible to make in_array() case insensitive, or is there another function I can use?
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: in_array() - case insensitive

Post by requinix »

in_array doesn't do string searching. It doesn't know what case-insensitivity means.

If there isn't a built-in function for this (I don't remember one), try your hand at a loop and strcasecmp.
JKM
Forum Contributor
Posts: 221
Joined: Tue Jun 17, 2008 8:12 pm

Re: in_array() - case insensitive

Post by JKM »

nevermind:

Code: Select all

$continue = in_array(strtolower($array), $extension) ? true : false;
Post Reply