note 44691 deleted from tutorial.useful by nlopess
| From: | nlopess@php.net | Date: | Sun, 15 Aug 2004 00:26:04 +0000 |
| Subject: | note 44691 deleted from tutorial.useful by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-74655@lists.php.net to get a copy of this message | ||
Note Submitter: feline@penguin.servehttp.com
----
The example of a conditional that is chosen above is somewhat awkward. Using
if (strpos($a, $b) !== FALSE)
to test whether $b is contained in $a will fail exactly if $a begins with $b (since then strpos will
return zero which will be cast to 'false' upon comparison with a boolean).
It works in the specific case (since the USER_AGENT string will *probably* not start with the
letters "MSIE") but it feels like somewhat shoddy programming to rely on that and should
probably not be used as a programming sample in a tutorial.
A more rigorous way would be
if (strpos($a, $b) >= 0)
which does the same thing but includes the strpos==0 case.