From: Operating system: PHP version: Irrelevant Package: Strings related Bug Type: Feature/Change Request Bug description:Search first substring from list
Description: ------------ If we want to search first substrings from list, we should make multiple calls to strpos() for each substring. Using PCRE will slowdown performance. So, we need some new function like: int strpos_array(string $haystack, array $needles, string &$found [, int $offset = 0 ]) which will accept array of substrings in $needle, search first position of them. If nothing found then returns FALSE. If found any substring then assign it to $found and return its position. The function name is not important. Other functions for case-insensitive search and/or for reverse search (stripos_array, strrpos_array, strripos_array) also useful. Extending function strpos() to accept array in $needle is not good due to &$found parameter. Good example of using such function is writing parser of some data like SQL dump. Performance of the function should be higher then PCRE. Test script: --------------- $string = 'foo;bar::baz-qwe'; $search = array('-', ';', '::'); $pos = strpos_array($string, $search, $found, 5); if ($pos === false) { echo "Nothing found"; } else { echo "Found '$found' at $pos"; } Expected result: ---------------- Found '::' at 7 -- Edit bug report at http://bugs.php.net/bug.php?id=51335&edit=1 -- Try a snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=51335&r=trysnapshot52 Try a snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=51335&r=trysnapshot53 Try a snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=51335&r=trysnapshot60 Fixed in SVN: http://bugs.php.net/fix.php?id=51335&r=fixed Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=51335&r=needdocs Fixed in release: http://bugs.php.net/fix.php?id=51335&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=51335&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=51335&r=needscript Try newer version: http://bugs.php.net/fix.php?id=51335&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=51335&r=support Expected behavior: http://bugs.php.net/fix.php?id=51335&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=51335&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=51335&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=51335&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=51335&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=51335&r=dst IIS Stability: http://bugs.php.net/fix.php?id=51335&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=51335&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=51335&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=51335&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=51335&r=mysqlcfg