1 回答
TA贡献1898条经验 获得超8个赞
(brackets)(^|_)([a-z])
/e\1'\\1'evaleval
preg_replace_callback'\\1'function($matches) { ... }$matches[1]
/e
'do_stuff(\\1) . "and" . do_stuff(\\2)'
function($m) { return do_stuff($m[1]) . "and" . do_stuff($m[2]); }'strtoupper("\\2")'function($m) { return strtoupper($m[2]); }$m$matchesarray($object, $method),
function stuffy_callback($things) {
return do_stuff($things[1]) . "and" . do_stuff($things[2]);}$foo = preg_replace_callback('/([a-z]+) and ([a-z]+)
/', 'stuffy_callback', 'fish and chips');use
'do_stuff(\\1, $foo)'
function($m) use ($foo) { return do_stuff($m[1], $foo); }格查斯
使用 preg_replace_callback是 而不是
这个 /e正则表达式上的修饰符,因此您需要从“模式”参数中移除该标志。所以像这样的模式 /blah(.*)blah/mei会变成 /blah(.*)blah/mi.这个 /e修饰语使用的变体 addslashes()内部的参数,所以一些替换使用 stripslashes()若要删除它;在大多数情况下,您可能希望删除对 stripslashes你的新电话。
- 1 回答
- 0 关注
- 642 浏览
添加回答
举报
