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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: haktan at cybercity dot dk
New email:
PHP Version: OS:

 

 [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

Pull Requests

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-2025 The PHP Group
All rights reserved.
Last updated: Wed Jul 02 06:01:38 2025 UTC