Re: [PHP-DEV] Bug #1540 Updated: strpos(): returning FALSE or 0 is the same From: Adam Trachtenberg (adam <email protected>)
Date: 06/15/99

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 <email protected>           | http://www.student.com    /

-- PHP Development Mailing List (http://www.php.net/) To unsubscribe, e-mail: php-dev-unsubscribe <email protected> For additional commands, e-mail: php-dev-help <email protected> To contact the list administrators, e-mail: php-list-admin <email protected>