Re: Bug #1540 Updated: strpos(): returning FALSE or 0 is the same
| From: | Adam Trachtenberg | Date: | Tue, 15 Jun 1999 14:38:49 +0000 |
| Subject: | Re: Bug #1540 Updated: strpos(): returning FALSE or 0 is the same | ||
| References: | 1 | Groups: | php.dev |
| Request: | Send a blank email to php-dev+get-6987@lists.php.net to get a copy of this message | ||
On 15 Jun 1999, Bug Database wrote:
> Basically, you're using the wrong function. Try strstr():
>
> <?
> if (strstr("abcde","a")) {
> echo "it's in there";
> } else {
> echo "it's not";
> }
> ?>
This won't work in sneaky cases like this:
if (strstr("I am a string that ends in 0","0")) {}
You're better off doing:
if (is_int(strpos($haystack,$needle))) {}
This will always work correctly, since is_int(0) returns true, while
is_int('') returns false.
-adam
--
/ adam maccabee trachtenberg | visit college life online \
\ adam@student.net | http://www.student.com /