php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #43825 Suggestion for new "substring exists" function
Submitted: 2008-01-12 01:10 UTC Modified: 2008-01-28 23:55 UTC
Votes:2
Avg. Score:3.0 ± 2.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:0 (0.0%)
From: anon at example dot com Assigned:
Status: Not a bug Package: Feature/Change Request
PHP Version: 5.2.5 OS:
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: anon at example dot com
New email:
PHP Version: OS:

 

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

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)


That "anti-FALSE" approach is generally awkward, and if you use == or 
!= by mistake you'll have ambiguity with a substring position of 
number 0.


It would be handy and much less prone to syntax mistakes, to have a 
dedicated "string exists" function which returns only TRUE or FALSE.

This might be "strex" or "strpres" ("string present").

Plus an equivalent case sensitive version -- striex or stripres.


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-01-28 23:55 UTC] tony2001@php.net
.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Fri Jul 04 17:01:35 2025 UTC