RE: preg_match too greedy

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> -----Original Message-----
> From: b [mailto:php@xxxxxxx]
> 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@xxxxxxxxxxxxxx 
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

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux