RE: [PHP] preg_match too greedy

From: Date: Fri, 31 Jul 2009 10:51:23 +0000
Subject: RE: [PHP] preg_match too greedy
References: 1 2 3 4  Groups: php.general 
Request: Send a blank email to php-general+get-296104@lists.php.net to get a copy of this message
> -----Original Message----- > From: b [mailto:php@logi.ca] > Sent: 30 July 2009 03:17 > > > > > >>> echo (preg_match($pattern, $test) != false) > > > > The " != false " here is redundant. > > Understood. But what you think is redundancy is, to me, clarity in > programming. I happen to think that boolean tests shouldn't ride on > whether or not an array returned from a function is empty or not (or > a > freaking boolean). If what I'm looking for is a "false" then that's > what > I'll test for. Well, then, by that logic you should be testing separately for ===FALSE and ===0, since the former means an error occurred, whilst the latter means the pattern was ok but didn't match. If the pattern finds a match, the return value is 1 (not TRUE). Cheers! Mike -- Mike Ford, Electronic Information Developer, Libraries and Learning Innovation, Leeds Metropolitan University, C507, Civic Quarter Campus, Woodhouse Lane, LEEDS,  LS1 3HE,  United Kingdom Email: m.ford@leedsmet.ac.uk Tel: +44 113 812 4730 To view the terms under which this email is distributed, please go to http://disclaimer.leedsmet.ac.uk/email.htm

« previous php.general (#296104) next »