From: anon at example dot com Operating system: PHP version: 5.2.5 PHP Bug Type: Feature/Change Request Bug description: Suggestion for a "Substring is Present" Function
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 bug report at http://bugs.php.net/?id=44334&edit=1 -- Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=44334&r=trysnapshot52 Try a CVS snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=44334&r=trysnapshot53 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=44334&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=44334&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=44334&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=44334&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=44334&r=needscript Try newer version: http://bugs.php.net/fix.php?id=44334&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=44334&r=support Expected behavior: http://bugs.php.net/fix.php?id=44334&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=44334&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=44334&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=44334&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=44334&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=44334&r=dst IIS Stability: http://bugs.php.net/fix.php?id=44334&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=44334&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=44334&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=44334&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=44334&r=mysqlcfg