Re: Inconsistent String Definition (string position starts at zero)?

From: Date: Sun, 26 Nov 2000 02:53:17 +0000
Subject: Re: Inconsistent String Definition (string position starts at zero)?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-27213@lists.php.net to get a copy of this message
On Sun, 26 Nov 2000, Adam Warner wrote: > Hi all, > > I had previously discovered (after searches within strings weren't working > properly) that string characters in PHP3 begin at position 0 (zero). This in > itself seems obtuse. But there is a more serious problem. > > For example: > $t="text string" > > Therefore: > strpos($t, "text") evaluates as 0. > > Because of this definition you can't use this conditional test below to test > whether a string contains a subset of characters: > > if (strpos($t,"text")==true) ... > > ...because it can evaluate as false even when the string contains the > characters you are looking for! (false=0 per the PHP manual). > > This also seems to seems to contradict the PHP3 manual for strpos: > If needle is not found, returns false. > > (Well it's not a direct contradiction, but it seems to be highly unhelpful > because if needle is found it can also return false). > > Is there something I am doing wrong (or have configured wrong) or does PHP > just have this inconsistency? > > Many thanks, > Adam Warner > Try: if (strpos($t,"text")!==false) ... The PHP manual has an omission about the Boolean type and its two possible values (true and false), but that's not quite the problem you're having here. -- Ignacio Vazquez-Abrams <ignacio@openservices.net>

« previous php.general (#27213) next »