> -----Original Message----- > From: Hawk [mailto:[EMAIL PROTECTED]] > Sent: 23 September 2002 12:33 > To: [EMAIL PROTECTED] > Subject: [PHP] == case-sensitive? > > > I've never really payed attention to this before, but now I > noticed that == > is case-sensitive, how do I make it == with different "cases" ?
Use strcasecmp(): strcasecmp($a, $b) // returns 0 if strings match case-insensitive // non-zero if not This is slightly unfortunate in that the test you have to do is counter-intuitive: if (strcasecmp($a, $b)): // strings DON'T match else: // strings match case-insensitively endif; Nonetheless, I'd prefer this over case-converting both strings and then comparing, as you're only making a single function call to do a comparison with in-line conversion, as opposed to two function calls for the conversions and then a comparison as well. (I guess I ought to benchmark that -- although it seems "obvious", sometimes the obvious isn't!) Cheers! Mike --------------------------------------------------------------------- Mike Ford, Electronic Information Services Adviser, Learning Support Services, Learning & Information Services, JG125, James Graham Building, Leeds Metropolitan University, Beckett Park, LEEDS, LS6 3QS, United Kingdom Email: [EMAIL PROTECTED] Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php