Req #66792 [NEW]: add callback function to preg_match

From: Date: Thu, 27 Feb 2014 14:59:43 +0000
Subject: Req #66792 [NEW]: add callback function to preg_match
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-184456@lists.php.net to get a copy of this message
From: crayonviolent at phpfreaks dot com Operating system: PHP version: Irrelevant Package: PCRE related Bug Type: Feature/Change Request Bug description:add callback function to preg_match Description: ------------ Pretty straightforward.. Add callback function capability to preg_match and preg_match_all. The requirements should be to ultimately return true or false. If true then it will count as a match. If false, it will not count as a match. This solution would allow injection of arbitrary logic, and I feel this will both greatly enhance and simplify a lot of common scenarios that benefit from using regex, but are unnecessarily complex because of limitations of regex, e.g number ranges and dates. Test script: --------------- /* use case: I expect an integer range from user, and I want to make sure the 'min' number is less than or equal to the 'max' num */ $string = "45-50"; if ( preg_match('~^(\d+)-(\d+)$~', $string, $match, function($m) { return ($m[1] <= $m[2]); } ) { // valid } else { // invalid } -- Edit bug report at https://bugs.php.net/bug.php?id=66792&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=66792&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=66792&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=66792&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=66792&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=66792&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=66792&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=66792&r=needscript Try newer version: https://bugs.php.net/fix.php?id=66792&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=66792&r=support Expected behavior: https://bugs.php.net/fix.php?id=66792&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=66792&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=66792&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=66792&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=66792&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=66792&r=dst IIS Stability: https://bugs.php.net/fix.php?id=66792&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=66792&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=66792&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=66792&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=66792&r=mysqlcfg

« previous php.bugs (#184456) next »