Re: comparisons
| From: | Andrey Hristov | Date: | Fri, 22 Mar 2002 14:03:29 +0000 |
| Subject: | Re: comparisons | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-89683@lists.php.net to get a copy of this message | ||
From the docs :
Note: It is easy to mistake the return values for "character found at position 0" and
"character not found". Here's how to detect
the difference:
// in PHP 4.0b3 and newer:
$pos = strpos($mystring, "b");
if ($pos === false) { // note: three equal signs
// not found...
}
// in versions older than 4.0b3:
$pos = strpos($mystring, "b");
if (!is_integer($pos)) {
// not found...
}
Andrey
----- Original Message -----
From: "Rick Emery" <remery@excel.com>
To: "'Andrey Hristov'" <ahristov@icygen.com>; "Rick Emery"
<remery@excel.com>
Cc: <php-general@lists.php.net>
Sent: Friday, March 22, 2002 3:58 PM
Subject: RE: [PHP] comparisons
> Andrey, you are incorrect.
>
> From the manual on strpos():
> int strpos (string haystack, string needle [, int offset])
> If needle is not found, returns FALSE.
>
> -----Original Message-----
> From: Andrey Hristov [mailto:ahristov@icygen.com]
> Sent: Friday, March 22, 2002 7:47 AM
> To: Rick Emery
> Cc: php-general@lists.php.net
> Subject: Re: [PHP] comparisons
>
>
>
> > if (ereg("john",$jeff) ) { }
> >
> ok
> > or:
> >
> > if( strstr( $jeff, "john") ) { }
> >
> ok
> > or:
> >
> > if( strpos( $jeff, "john") ) { }
> error
>
> if (strpos($jeff, "john") !== FALSE)
>
> Best regards,
> Andrey Hristov
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>