php - How to call a function inside an array that save matches rules -


i'm trying call function inside 1 array using matches.

i have string text ($text) , 2 arrays.

the array have rules find content:

$a=array('rule1', 'rule2', rule3'); 

the array b have:

$b=array("rule 1 return matches: $1 $2 $3", "rule 2: $1 $2 $3", "rule 3 $1 $2 $3"); 

and foreach loop, arrays make work:

foreach($a $key => $val){     while(preg_match($val, $text)){         $text = preg_replace($val, $b[$key], $text);     } } 

exist method? array b:

$b=array("rule 1 return matches:".calltofunction("$1$2$3")."", ... 

i tried use \1 , $1 matches, when call function every time function receives string "$1$2$3" or "\1\2\3" not matched values.

regards!

this seems not possible, array save rules, yes can used save rules. b needed make custom function per each one.

function myfunction($text) {     return preg_replace_callback($a[the num id],     function($match) {         return "this return matches: $match[1] $match[2] $match[3]";     }     , $text); } 

Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -