php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #13730 StrPos is deficient
Submitted: 2001-10-18 05:42 UTC Modified: 2003-01-18 13:07 UTC
Votes:1
Avg. Score:4.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: anthony at syntell dot net Assigned:
Status: Closed Package: Feature/Change Request
PHP Version: 4.0.6 OS: Linux/Red Hat 7.1
Private report: No CVE-ID: None
 [2001-10-18 05:42 UTC] anthony at syntell dot net
re StrPOS, I suggest that you do the following.

Make another function with a different name, e.g. StrFind, that is
1) less problematic in distinguishing between found at pos zero and not found. e.g. return -1 for not found.
2) case-insensitive, or (better) has an optional parameter ($casesensitive = false) that defaults to false

You could also roll in last-occurence functionality a la strrpos with option flags

After this, mark the StrPos function as obsolete/deprecated.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-02-19 14:18 UTC] dadarden at iti2 dot net
Or make the string position one based instead of zero based so that a return of 0 can be used for false and any other return is true.  strstr() can usually be used that way, but seems to get confused looking for "/".
 [2003-01-18 12:49 UTC] andrey@php.net
 Even though PHP is loosed type language there is === operator for checking the types as well the values. If the developer is lazy to write !== FALSE then he/she can get the flames after that because he/she deserves them. This will break BC and won't be implemented. 
Regarding the "one based" string position. PHP is like C, not Pascal.
 [2003-01-18 13:07 UTC] philip@php.net
Also this behavior is documented.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Jul 23 23:00:03 2025 UTC