RE: [PHP] strpos mystery

From: Date: Thu, 29 Jul 2004 10:03:23 +0000
Subject: RE: [PHP] strpos mystery
Groups: php.general 
Request: Send a blank email to php-general+get-192167@lists.php.net to get a copy of this message
On 29 July 2004 01:50, Jon Drukman wrote: > with this code fragment: > > <? > > $string='/mobile/phone.html'; > if (strpos($string,'/mobile/')!==false) { print "one: yes\n"; } > if (strpos($string,'/mobile/')===true) { print "two: yes\n"; } > > > > > > only the first if statement prints anything. why is !== > false not the > same as === true ? Because strpos returns the integer offset of the found substring, or FALSE if not found; it *never* returns TRUE. (You need the !== test because strpos() can return an offset of zero, which would be ==FALSE but not ===FALSE.) Cheers! Mike --------------------------------------------------------------------- Mike Ford, Electronic Information Services Adviser, Learning Support Services, Learning & Information Services, JG125, James Graham Building, Leeds Metropolitan University, Headingley Campus, LEEDS, LS6 3QS, United Kingdom Email: m.ford@leedsmet.ac.uk Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211

« previous php.general (#192167) next »