RE: [PHP] == case-sensitive?

From: Date: Mon, 23 Sep 2002 12:11:40 +0000
Subject: RE: [PHP] == case-sensitive?
Groups: php.general 
Request: Send a blank email to php-general+get-117263@lists.php.net to get a copy of this message
> -----Original Message----- > From: Hawk [mailto:hw2k@barrysworld.com] > Sent: 23 September 2002 12:33 > To: php-general@lists.php.net > 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: m.ford@lmu.ac.uk Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211

« previous php.general (#117263) next »