| 
        php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login | 
  [2010-06-19 12:13 UTC] vovan-ve at yandex dot ru
 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) PatchesPull Requests
Pull requests: 
 HistoryAllCommentsChangesGit/SVN commits             
             | 
    |||||||||||||||||||||||||||||||||||||
            
                 
                Copyright © 2001-2025 The PHP GroupAll rights reserved.  | 
        Last updated: Tue Nov 04 11:00:01 2025 UTC | 
I have some doubts that this functionality is required often enough to warrant adding it to PHP, considering that it can easily be implemented in userland (without making a copy of the string): function strpos_len($haystack, $needle, $offset, $length) { $pos = strpos($haystack, $needle, $offset); if ($pos > $offset + $length - strlen($needle)) { $pos = false; } return $pos; }