note 44691 added to tutorial.useful
| From: | feline at penguin dot servehttp dot com | Date: | Fri, 13 Aug 2004 00:54:43 +0000 |
| Subject: | note 44691 added to tutorial.useful | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-74570@lists.php.net to get a copy of this message | ||
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.
----
Manual Page -- http://www.php.net/manual/en/tutorial.useful.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+44691
Delete -- http://master.php.net/manage/user-notes.php?action=delete+44691&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+44691&report=yes
Search -- http://master.php.net/manage/user-notes.php