RE: [PHP] Case insensitive string comparison!
| From: | Peter Johansson | Date: | Wed, 12 Jul 2000 16:30:02 +0000 |
| Subject: | RE: [PHP] Case insensitive string comparison! | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-6180@lists.php.net to get a copy of this message | ||
> This seems kinda overkill to me, but maybe this really is the way
> to compare
> multiple strings?? The manual doesn't mention anything about this... But
> calling strcasecmp each time??
>
> if ((!strcasecmp ($ext, ".html")) || (!strcasecmp ($ext, ".htm"))
> {
> echo 'We have a match..';
> }
Since I'm a fan of regular expressions for these kind of things I'd use
something like:
if (!preg_match("/\.html?$/i", $ext)) {
echo "Houston, we have a problem...";
}
Less writing for (almost) the same result. Anchoring the beginning of the
pattern aswell (with a ^) should result in an identical solution to the one
using strcasecmp(). I haven't compared operations like this
performance-wise, anyone who has? If the regexp is dog-slow, I can always
re-evaluate my personal opinion :)
Regards,
Peter