#44029 [Opn->Bgs]: Suggestion for new "substring exists" function
| From: | rasmus@php.net | Date: | Sun, 03 Feb 2008 16:15:18 +0000 |
| Subject: | #44029 [Opn->Bgs]: Suggestion for new "substring exists" function | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-121925@lists.php.net to get a copy of this message | ||
ID: 44029
Updated by: rasmus@php.net
Reported By: anon at example dot com
-Status: Open
+Status: Bogus
Bug Type: Feature/Change Request
PHP Version: 5.2.5
New Comment:
We already have strstr()
Previous Comments:
------------------------------------------------------------------------
[2008-02-03 07:46:09] whatever at yahoo dot com
I entered this suggestion previously as bug #43825 -- which got closed
as Bogus with no note.
Please explain why it is "bogus" if closing again. If tony2001@php.net
thinks there is no usability problem with detecting the simple
existence
of a substring in a string, he should examine the commentary in
http://us3.php.net/manual/en/function.strpos.php.
If there's some other
function that already does what I'm suggesting please indicate what it
is.
------------------------------------------------------------------------
[2008-02-03 07:43:02] 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 when examining a user agent -- is
"MSIE" there or not?
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.
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=44029&edit=1