Re: What could the intention be of someone using "\0" in comparison be?
| From: | Christoph Becker | Date: | Tue, 19 Aug 2014 13:58:48 +0000 |
| Subject: | Re: What could the intention be of someone using "\0" in comparison be? | ||
| References: | 1 | Groups: | php.windows |
| Request: | Send a blank email to php-windows+get-31300@lists.php.net to get a copy of this message | ||
Jacob Kruger wrote:
> As in, while my first guess would be that they'd meant to use just the
> number 0, what would your guesstimate be relating to why someone would in
> fact use the following syntax as part of determining if a certain
> phrase/string was included in a variable's value?
>
> //start excerpt...
> if (strpos ($text, "<b>") >= "\0")
> //end excerpt
>
> ???
Well, using "0" or 0 instead of "\0" would result in unintended
behavior. Consider strpos() returning 0, because the $needle is found
at the very beginning of $haystack. See <http://3v4l.org/0uaY6>, where
the second and third results are not desired.
However, I prefer the following way to test that a string is contained
in another string:
if (strpos($haystack, $needle) !== false)
--
Christoph M. Becker