note 56347 added to function.strncasecmp

From: Date: Wed, 31 Aug 2005 10:43:11 +0000
Subject: note 56347 added to function.strncasecmp
Groups: php.notes 
Request: Send a blank email to php-notes+get-94516@lists.php.net to get a copy of this message
Hi all, be aware when comparing strings using the strcmp family. if you write code like this... if (strncasecmp($string, 'Trudeau', 4)) print "true"; The above code returns 1 which evaluates to boolean 'true' that statement will always be true... because these functions return 0 only when equal. so a better test would be if ( (strncasecmp($string, 'Trudeau', 4)) == 0) print "true"; always test these functions equality with 0 regards ---- Manual Page -- http://www.php.net/manual/en/function.strncasecmp.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+56347 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+56347&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+56347&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+56347&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+56347&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+56347&report=yes&reason=non-english Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+56347&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+56347&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#94516) next »