This code:
$t = 100;
$str = preg_replace_callback("/(Name[A-Z]+[0-9]*)/",
create_function(
'$matches',
'return $matches[1] + $t;'
), $func);
How to make $t visible from create_function() in preg_replace() function?
function($matchtes)use($t){/*..*/}
– KingCrunch Apr 12 '12 at 20:32"1" + 100
;) But I see, what you mean: The regular expression matches something starting withName
, thus the function will always return100
(=$t
). Probably not wanted. – KingCrunch Apr 12 '12 at 20:49use
construct. This requires at least PHP 5.3. BTW, if the value of $t doesn't every change, you might consider using a constant which will be available in any context. – wilmoore Apr 12 '12 at 22:29