此代码:PHP:如何使变量在create_function()中可见?
$t = 100;
$str = preg_replace_callback("/(Name[A-Z]+[0-9]*)/",
create_function(
'$matches',
'return $matches[1] + $t;'
), $func);
如何使$ T从的preg_replace()函数create_function()可见?
您应该使用,而不是封'http://php.net/functions.anonymous功能($ matchtes)使用($ T){/*..*/}' – KingCrunch 2012-04-12 20:32:51
嗯+操作上串? – hakre 2012-04-12 20:42:23
@hakre''1“+ 100';)但是我明白了,你的意思是:正则表达式匹配以'Name'开头的东西,因此函数总是返回'100'('= $ t')。可能不想要。 – KingCrunch 2012-04-12 20:49:36