Bug #1323: strpos and 0th indexed strings

From: Date: Fri, 16 Apr 1999 18:09:27 +0000
Subject: Bug #1323: strpos and 0th indexed strings
Groups: php.dev 
Request: Send a blank email to php-dev+get-5101@lists.php.net to get a copy of this message
From: maarnold@gte.net Operating system: linux PHP version: 3.0.5 PHP Bug Type: Misbehaving function Bug description: strpos and 0th indexed strings strpos() returns false if needle is not found in haystack. false is 0. Strings are indexed starting at 0. How should the caller of strpos() that strpos() didn't find the character at the beginning of the string. For example,... printf( "pos is %d<br>\n", strpos( "abcdefg", "z" ) ); printf( "result is %s<br>\n", ( strpos( "abcdefg", "z" ) ) ? "true" : "false" ); printf( "pos is %d<br>\n", strpos( "abcdefg", "a" ) ); printf( "result is %s<br>\n", ( strpos( "abcdefg", "a" ) ) ? "true" : "false" ); ...displays... pos is 0 result is false pos is 0 result is false Most languages that have 0th indexed strings have strpos() return -1 when needle is not found in haystack. Either that, or the language has a special value for false (such as NULL instead of 0). -- PHP Development Mailing List http://www.php.net/ To unsubscribe send an empty message to php-dev-unsubscribe@lists.php.net For help: php-dev-help@lists.php.net

« previous php.dev (#5101) next »