Re: Is this a bug ??

From: Date: Thu, 31 Aug 2000 12:26:31 +0000
Subject: Re: Is this a bug ??
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-14569@lists.php.net to get a copy of this message
ti980246@binus.ac.id wrote: > hellow.. is 0 equal with null ?? > i've written a code using strpos to get position of substring in a string.. here > is my snippet.. > $besar="Sam"; > $posisi=strpos($besar,"S"); > if ($posisi=="") {print("NULL");} > if ($posisi==0) {print("first position");} > it runs the both if (it prints "NULL and "first position") > the second if means that the substring is on first position in a string... but it > is a null too.. is this a bug ?? or i've misunderstanding the php's variable > concept ? > thank's As the manual states in the documentation of strpos(), you should use operator === (is equal and of same type) to make difference between the first position and the FALSE/null value. Thus (for PHP 4): <?php $besar = "Sam"; $posisi = strpos( $besar, "S" ); if (!isset($posisi) || $posisi === FALSE) { print "Not found."; } else { print "'S' found at $besar in position $posisi: '$besar[$posisi]'\n"; } ?> -- | Heikki Korpela | heikki.korpela@wapit.com | tel. +358 50 3838 609 | | Software Developer, Wapit Finland | http://www.wapit.com | -- Over the centuries, mankind has tried many ways of combating the forces of evil...prayer, fasting, good works and so on. Up until Doom, no one seemed to have thought about the double-barrel shotgun. Eat leaden death, demon... -- (Terry Pratchett, alt.fan.pratchett)

« previous php.general (#14569) next »