0

our old code base is using something like below:

$x = $this->$getParsing();
$c = preg_replace('|site://([\w\-]+?)/([\w\-]+?)/([\w\-\/\.]+)?|e','$x->getList(\'$1\', \'$2\', \'$3\')',$c);

print_r($c);
Avinash Raj
  • 172,303
  • 28
  • 230
  • 274
josheph j
  • 9
  • 1
  • if I understand your statement... check this: http://php.net/manual/en/function.preg-replace-callback.php – Dale May 20 '16 at 13:40
  • @NMoeini No, this is not a duplicate. `preg_replace_callback` takes one match at a time. The OP was using /e option to deal with a callback taking **multiple** matches as multiple arguments. `preg_replace_callback` cannot take multiple arguments. – Aleks G May 20 '16 at 13:41
  • @Aleks G, are you positive? You can pass all matches as an array to the function callback and also pass multiple arguments to use. – Navid May 20 '16 at 13:45
  • It is a duplicate as the answer explains how to pass a variable to the callback function. – Wiktor Stribiżew May 20 '16 at 13:46
  • @WiktorStribiżew OP doesn't need to pass a variable, he needs to pass more than one match into the same function. – Aleks G May 20 '16 at 13:54
  • @josheph j, as this has been closed as duplicate I post here a direct answer. Test it. `$c = preg_replace_callback('|site://([\w\-]+?)/([\w\-]+?)/([\w\-\/\.]+)?|', function($m) use ($x) { return $x->getList($m[1], $m[2], $m[3]);} ,$c);` – Navid May 20 '16 at 14:51
  • Of course, and it is perfectly in line with the duplicate status of the question. – Wiktor Stribiżew May 23 '16 at 06:49
  • Thanks all for your suggestions. – josheph j Jun 06 '16 at 05:59

0 Answers0