#40182 [NEW]: Want a function strpos_all with optional parameters

From: Date: Sat, 20 Jan 2007 19:26:32 +0000
Subject: #40182 [NEW]: Want a function strpos_all with optional parameters
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-107824@lists.php.net to get a copy of this message
From: krudtaa at yahoo dot com Operating system: all PHP version: 5.2.0 PHP Bug Type: Feature/Change Request Bug description: Want a function strpos_all with optional parameters Description: ------------ I would very much like to see a function that returns all positions of a needle within a haystack. Similar to strpos but named to strpos_all And should return an array with all positions of needle within haystack. Should also be able to take at least two optional parameters as well: one arithmetic operator one number see below for explanation of why and motivation. My specific need is to be able to search a string 5000 chars in length which consist of only zeroes and ones (0 or 1). And I want to get position of all chars set to 1. I read through the comments on www.php.net/strpos and the closest solution I could find to what I wanted was this: $bitvec = str_repeat('1',5000); $posArr = array(); // next two lines from www.php.net/strpos comments $pos=-1; // need this to start on first element while ( ($pos = strpos($bitvec4,'1',$pos+1)) !== false ) $posArr[]=$pos ; The above is worst case. Normally, for my use, the bitvector, $bitvec, would not have all chars set to 1, but it will happen. Using the above code to get all the positions where char = 1 is so much slower compared to if someone could write a function that handles this. IMHO I think this is something many could use. To make this "new" function "strpos_all" even better, if possible, I would like it to be able to pass two other values: one number and one arithmetic operator If these are set then I want the value to be stored in the array element to be (if arithmetic operator was *) Position * number If the new function could NOT do this then, at least I, would have to iterate through all the elements to change the values which again would take a "long" time if done on each element in PHP compared to if done within the "upcoming" strpos_all function. Really hope to see a function that can do this. My goal is to use PHP and database to build a fast Seach Engine using a combination of "vectorspace" and "reversed index". In short I want to do what TBGsearch does with PERL and MYSQL, but using PHP and MYSQL: http://www.tbg.nu/tbgsearch/ The one thing so far that slow my "PHP solution" to much down is the lack of strpos_all string with my suggested optional parameters (one artithmetic operator and one number). Keep up the good work! -- Edit bug report at http://bugs.php.net/?id=40182&edit=1 -- Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=40182&r=trysnapshot44 Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=40182&r=trysnapshot52 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=40182&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=40182&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=40182&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=40182&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=40182&r=needscript Try newer version: http://bugs.php.net/fix.php?id=40182&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=40182&r=support Expected behavior: http://bugs.php.net/fix.php?id=40182&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=40182&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=40182&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=40182&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=40182&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=40182&r=dst IIS Stability: http://bugs.php.net/fix.php?id=40182&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=40182&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=40182&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=40182&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=40182&r=mysqlcfg

« previous php.bugs (#107824) next »