php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #43824 Suggestion for new "substring exists" function
Submitted: 2008-01-12 00:31 UTC Modified: 2008-01-12 00:57 UTC
From: anon at example dot com Assigned:
Status: Closed Package: Feature/Change Request
PHP Version: 5.2.5 OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: anon at example dot com
New email:
PHP Version: OS:

 

 [2008-01-12 00:31 UTC] anon at example dot com
Description:
------------
What we often need to test for is just whether a substring exists or not. This is very common, for example, in examining a user agent.

Currently you have to test for these specific formulations, being very careful to use the strict equivalency operators:

	strpos === FALSE

or

	strpos !== FALSE



It would be handy and much less prone to incorrect syntax use to have a "string exists" function -- maybe as strex or strpres ("string present") -- dedicated to this, which returns only TRUE or FALSE.

There could also be a "case sensitive string exists" -- maybe as striex or stripres.


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-01-12 00:47 UTC] anon at example dot com
In case my initial description is confusing, I mean...


Currently you can use strpos, but you have to be careful to test only with two specific formulations, using the strict equivalency operators: 

	if (strpos($x, $y) === FALSE)

or

	if (strpos($x, $y) !== FALSE)


Otherwise you will have ambiguity with a substring position of number 0.
 [2008-01-12 00:57 UTC] anon at example dot com
Closing this and replacing with new coherent bug.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 18 21:01:29 2024 UTC