Re: Re: PHP 4.0 Bug #3017 Updated: if(strpos("Mozilla/4.7", "Mozilla") evaluates false!!!
| From: | Andrei Zmievski | Date: | Tue, 21 Dec 1999 18:13:57 +0000 |
| Subject: | Re: Re: PHP 4.0 Bug #3017 Updated: if(strpos("Mozilla/4.7", "Mozilla") evaluates false!!! | ||
| References: | 1 2 | Groups: | php.dev |
| Request: | Send a blank email to php-dev+get-13913@lists.php.net to get a copy of this message | ||
On Tue, 21 Dec 1999, Cuneyt YILMAZ wrote:
> thank you for the fast response. however the function still does not
> behave as one would expect.
>
> that strpos("Mozilla/4.7", "Mozilla") is 0 should not mean that it's
> not
> found, instead should mean that it's found right on the 0th position,
> and therefore in an if-clause should evaluate to true.
>
> i know there are many workarounds to this problem, like
> if (substr($uagent, 0, 7) == "Mozilla)) {
> or
> if (strpos($uagent, "ozilla") == 1 ) {
> etc, etc
>
> yet the strpos function still does not behave as expected, ie return -1
> if not found as in the other languages, say C/C++, Java, JavaScript,
> Perl, to name a few giants.
The semantics of strpos() are not going to change and if() will
certainly not evaluate 0 as true. I offered you a workaround - to see
whether the match succeeded or not try:
if (strpos($uagent, "Mozilla") === false)
means that match was not found.
-Andrei
* On the keyboard of life, always keep one finger on the escape key. *