From: Operating system: PHP version: Irrelevant Package: Strings related Bug Type: Feature/Change Request Bug description:[strpos] Limit search inside $haystack by new $length parameter
Description: ------------ Why strpos() does not accept $length parameter with addition to $start? It would be very useful to search a $needle inside a part of $haystack sometimes. Now such behaviour can be made by combination with substr(): $string = 'The big string [with some data here] and with more data there'; // searh inside substring from offset 16 with length 19 $tmp = substr($string, 16, 19); // now real search $pos = strpos($tmp, 'data'); if (false !== $pos) $pos += 16; // original position var_dump($pos); It work, but not optimal due to redundant copy of substring. I don't need this copy, I just want to reduce searching area. Test script: --------------- $string = 'The big string [with some data here] and with more data there'; // search 'data' inside substring from offset 16 with length 19 $pos = strpos($string, 'data', 16, 19); var_dump($pos); Expected result: ---------------- int(26) -- Edit bug report at http://bugs.php.net/bug.php?id=52124&edit=1 -- Try a snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=52124&r=trysnapshot52 Try a snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=52124&r=trysnapshot53 Try a snapshot (trunk): http://bugs.php.net/fix.php?id=52124&r=trysnapshottrunk Fixed in SVN: http://bugs.php.net/fix.php?id=52124&r=fixed Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=52124&r=needdocs Fixed in release: http://bugs.php.net/fix.php?id=52124&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=52124&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=52124&r=needscript Try newer version: http://bugs.php.net/fix.php?id=52124&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=52124&r=support Expected behavior: http://bugs.php.net/fix.php?id=52124&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=52124&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=52124&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=52124&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=52124&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=52124&r=dst IIS Stability: http://bugs.php.net/fix.php?id=52124&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=52124&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=52124&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=52124&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=52124&r=mysqlcfg
