php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #2563 strpos returns the same result for "not found" and "found at 1st character"
Submitted: 1999-10-18 18:16 UTC Modified: 1999-10-31 10:34 UTC
From: sascha dot mantscheff at t-online dot de Assigned:
Status: Closed Package: Misbehaving function
PHP Version: 3.0.11 OS: Suse Linux
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: sascha dot mantscheff at t-online dot de
New email:
PHP Version: OS:

 

 [1999-10-18 18:16 UTC] sascha dot mantscheff at t-online dot de
There seems to be no way to programatically differentiate between the meaning "substring not found" and "found at the 1st place in the substring". 

Consider the statements:

if (strpos( "abc", "a" ) == false)
  echo "false;

and

if (strpos( "abc", "a" ) == 0)
  echo "false";

They both print "false", though "a" is a substring of "abc". 

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [1999-10-31 10:34 UTC] rasmus at cvs dot php dot net
It's not ideal, but strpos() returns 0 when the char is found in the first position and an empty string when it isn't
found at all.  strlen(strpos()) would give you a proper true/false, for example.
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Mon Jun 29 18:00:01 2026 UTC