php3-list | 199908
Date: 08/12/99
- Next message: Derek Bruce: "[PHP3] 0 is not a result"
- Previous message: Oliver Schleede: "[PHP3] rEply: Apache server authentication"
- In reply to: Scott Shepherd: "[PHP3] strpos()"
- Next in thread: Steve Edberg: "Re: [PHP3] strpos()"
- Reply: Steve Edberg: "Re: [PHP3] strpos()"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Hi,
As they can't alter the function's behaviour now that it is in widespread
use, you'll
have to use a workaround.
The way I do it is, instead of
if (strpos($blah,"whatever"))
use
if (strpos("_$blah","whatever"))
Hence, it will only return 0 if "whatever" truly doesn't exist in the
haystack, anywhere. Just
better not go searching for the haystack for _ :)
You could try to use a character that is unlikely to be the start of a
string.. ie. the null character
(strpos is binary safe). ie. if (strpos("\0$blah","whatever"))
At 04:01 PM 8/8/99 -0400, Scott Shepherd wrote:
>am i missing something? strpos() seems useless because it returns the same
>thing if the needle is at the beginning of the haystack (0) or not in the
>haystack at all (false, ie 0). other languages get around this by having
>such functions return -1 for failure or throw an error flag or something.
>
>i just want to know "is the needle in the haystack?" i've resorted to if(
>strstr( $a, $b ) ) which works in my case, but that could be screwy too
>if, say, you're looking for "0" in a haystack that might be "0".
>
>--
>PHP 3 Mailing List <http://www.php.net/>
>To unsubscribe, send an empty message to php3-unsubscribe <email protected>
>To subscribe to the digest, e-mail: php3-digest-subscribe <email protected>
>To search the mailing list archive, go to: http://www.php.net/mailsearch.php3
>To contact the list administrators, e-mail: php-list-admin <email protected>
Regards,
Adam Whitehead
CEO - Netherworld Media
E-mail: adam <email protected>
Phone: +61 (889) 279 898
FAX: +61 (889) 273 889
Mobile: +61 (411) 241 120
Musicseek (http://www.musicseek.net)
-- PHP 3 Mailing List <http://www.php.net/> To unsubscribe, send an empty message to php3-unsubscribe <email protected> To subscribe to the digest, e-mail: php3-digest-subscribe <email protected> To search the mailing list archive, go to: http://www.php.net/mailsearch.php3 To contact the list administrators, e-mail: php-list-admin <email protected>
- Next message: Derek Bruce: "[PHP3] 0 is not a result"
- Previous message: Oliver Schleede: "[PHP3] rEply: Apache server authentication"
- In reply to: Scott Shepherd: "[PHP3] strpos()"
- Next in thread: Steve Edberg: "Re: [PHP3] strpos()"
- Reply: Steve Edberg: "Re: [PHP3] strpos()"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]

