1 回答

TA貢獻1898條經驗 獲得超8個贊
(brackets)
(^|_)
([a-z])
/e
\1
'\\1'
eval
eval
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
$matches
array($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 關注
- 603 瀏覽
添加回答
舉報