1 回答

TA貢獻(xiàn)1898條經(jīng)驗(yàn) 獲得超8個(gè)贊
(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
是 而不是
這個(gè) /e
正則表達(dá)式上的修飾符,因此您需要從“模式”參數(shù)中移除該標(biāo)志。所以像這樣的模式 /blah(.*)blah/mei
會(huì)變成 /blah(.*)blah/mi
.這個(gè) /e
修飾語使用的變體 addslashes()
內(nèi)部的參數(shù),所以一些替換使用 stripslashes()
若要?jiǎng)h除它;在大多數(shù)情況下,您可能希望刪除對(duì) stripslashes
你的新電話。
- 1 回答
- 0 關(guān)注
- 612 瀏覽
添加回答
舉報(bào)