note 80363 added to function.strpos
| From: | Suggestedre-writeforpinkWARNINGbox at osu1 dot php dot net | Date: | Fri, 11 Jan 2008 23:45:32 +0000 |
| Subject: | note 80363 added to function.strpos | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-135045@lists.php.net to get a copy of this message | ||
WARNING
As strpos may return either FALSE (substring absent) or 0 (substring at start of string), strict
versus loose equivalency operators must be used very carefully.
To know that a substring is absent, you must use:
=== FALSE
To know that a substring is present (in any position including 0), you can use either of:
!== FALSE (recommended)
> -1 (note: or greater than any negative number)
To know that a substring is at the start of the string, you must use:
=== 0
To know that a substring is in any position other than the start, you can use any of:
> 0 (recommended)
!= 0 (note: but not !== 0 which also equates to FALSE)
!= FALSE (disrecommended as highly confusing)
Also note that you cannot compare a value of "" to the returned value of strpos. With a
loose equivalence operator (== or !=) it will return results which don't distinguish between
the substring's presence versus position. With a strict equivalence operator (=== or !==) it
will always return false.
----
Server IP: 64.71.164.2
Probable Submitter: 76.201.168.43
----
Manual Page -- http://www.php.net/manual/en/function.strpos.php
Edit -- https://master.php.net/note/edit/80363
Del: integrated -- https://master.php.net/note/delete/80363/integrated
Del: useless -- https://master.php.net/note/delete/80363/useless
Del: bad code -- https://master.php.net/note/delete/80363/bad+code
Del: spam -- https://master.php.net/note/delete/80363/spam
Del: non-english -- https://master.php.net/note/delete/80363/non-english
Del: in docs -- https://master.php.net/note/delete/80363/in+docs
Del: other reasons-- https://master.php.net/note/delete/80363
Reject -- https://master.php.net/note/reject/80363
Search -- https://master.php.net/manage/user-notes.php