|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2004-10-07 09:07 UTC] derick@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Dec 18 10:00:02 2025 UTC |
Description: ------------ I use preg_replace_callback to substitute parts of an expression with either true or false after which the expression can be evaluated using eval: _q1,1,1-2 & _q2,3-4,7 should become true & false which can be evaluated to false. The strings represent answers to questions (it's for an interview system) The problem is that the answers are stored in a global array. The (global) array can not be read from a function that is called from preg_replace_callback It would be nice if somebody can fix this :-) Reproduce code: --------------- function parseqstring($qstring) { global $qre; preg_match_all('/(\d+-\d+|\d+)/', $qstring, $numbers); $q = array_shift($numbers[0]); foreach($numbers[0] as $number) { //if its a number check the answer if(is_numeric($number)) { //if the answer is there return true because it's all 'or' conditions if($qre[$q]['answers'][$number]==1) { return 'true'; } } //if its a range check all the numbers in the range if(preg_match('/(\d+)-(\d+)/', $number, $match)) { for($i=$match[1];$i<=$match[2];$i++) { if($qre[$q]['answers'][$i]) { return 'true'; } } } } return 'false'; } Expected result: ---------------- input: $qstring = _q1,1,3-4 $qre[1]['answers'][3] output: 'true' Actual result: -------------- 'false'