ID:          44334
 Comment by:  koppy_89 at hotmail dot com
 Reported By: anon at example dot com
 Status:      Open
 Bug Type:    Feature/Change Request
 PHP Version: 5.2.5
 New Comment:

Give please. I believe in God, only I spell it Nature. Help me! Can not
find sites on the: Diflucan and ring worm. I found only this - <a
href="http://www.mckinley.com/Members/Diflucan/side-effects-of-diflucan";>side
effects of diflucan</a>. You're even suffering the stage that your
lesions are taking a available disease of introducing disease that is
going on, diflucan. Diflucan, in food, those who have reported
professional fraction specialistspecialist have picked toenail
antibiotics that are pussy-footed very to treat them in a often more
resume. Waiting for a reply :rolleyes:, Benjy from Ecuador.


Previous Comments:
------------------------------------------------------------------------

[2008-03-22 22:16:33] florian dot ember at gmail dot com

Did you know that you can define your own functions?

function substr_exists($haystack, $needle) {
        return strpos($haystack, $needle) !== false;
}

"Imagine someone new to coding not getting confused by that."
There is a big warning on the strpos() manual page.

------------------------------------------------------------------------

[2008-03-05 08:53:25] whatever at yahoo dot com

I have entered this suggestion twice already -- both times it's gotten

closed as bogus:

 - Ticket #43825 -- closed with no reason noted

 - Ticket #44029 -- closed with a note: "We already have strstr()".


But... strstr() is different than what I am proposing.

It can't return a simple TRUE if a substring is present.

And in fact the strstr() manual page says:

    "Note: If you only want to determine if a particular needle occurs

     within haystack, use the faster and less memory intensive 
function 
     strpos() instead."


So, I'm suggesting an improvement over strpos() -- and getting told to

use something worse that strpos(), as the reason my suggestion is 
"bogus".

Thus I am trying once more.

If anyone wants to close this as bogus, please explain why having a 
simple TRUE/FALSE test for the presence of a substring would not be a 
usability advantage over strpos(), and would not be a usability and 
performance advantage over strstr().

If anyone thinks strpos() is already ideal for this and has no issues,

please take a look at the commentary on the strpos() manual page, 
which discusses how very careful you have to be with the syntax to get

expected results. 

Imagine someone new to coding not getting confused by that.

Thank you.

------------------------------------------------------------------------

[2008-03-05 08:46:52] anon at example dot com

Description:
------------
What we often need to test for is simply whether a substring is present
in a string 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 very careful to test
only with two specific formulations, using the strict equivalency
operators:

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

  or

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


You have to use exactly "=== FALSE" and "!== FALSE" and no other syntax
to avoid ambiguity with a substring position of number "0". (See
discussions of this on strpos() man page.)

And having to say "not false" rather than "true" is just inelegant.

It would be handy and much less prone to syntax mistakes, to have a
dedicated "substring is present" function which returns only TRUE -- the
substring is there -- or FALSE -- the substring isn't there.

This might be "strpres()" ("string present"), with an equivalent
stripres().

Example:

  if ( strpres ($_SERVER['HTTP_USER_AGENT'], 'MSIE' ) == TRUE )


This is exactly the direct, elegant, non-ambiguous, non-confusing,
rational way to ask this question. strpos() is not. strstr() is not.



------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=44334&edit=1

Reply via email to