php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #912 strpos returns 0, when strpos("abc", "a") returns 0, should be -1
Submitted: 1998-11-12 07:48 UTC Modified: 1998-11-12 08:27 UTC
From: haktan at cybercity dot dk Assigned:
Status: Closed Package: Misbehaving function
PHP Version: 3.0.5 OS: FreeBSD
Private report: No CVE-ID: None
 [1998-11-12 07:48 UTC] haktan at cybercity dot dk
strpos("abc","a") returns 0 because "a" is found at index 0.
strpos("abc","x") also returns 0 because "x" is not found.

It would be better if strpos returns -1 when search-string
not found.


-- Haktan Bulut

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [1998-11-12 08:27 UTC] rasmus
Not true.  strpos("abc","x") returns an empty string ("") not 0 while
strpos("abc","a") returns 0.  You can distinguish between the two
cases with something like: if(strlen(strpos("abc",$char)) echo "Found";
Returning -1 would be inconsistent with the rest of PHP.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed May 29 11:01:32 2024 UTC