Req #52124 [NEW]: [strpos] Limit search inside $haystack by new $length parameter
| From: | vovan-ve at yandex dot ru | Date: | Sat, 19 Jun 2010 10:13:02 +0000 |
| Subject: | Req #52124 [NEW]: [strpos] Limit search inside $haystack by new $length parameter | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-151619@lists.php.net to get a copy of this message | ||
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