Inconsistent String Definition (string position starts at zero)?
| From: | Adam Warner | Date: | Sun, 26 Nov 2000 03:49:15 +0000 |
| Subject: | Inconsistent String Definition (string position starts at zero)? | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-27212@lists.php.net to get a copy of this message | ||
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