非常簡單;我似乎無法找到有關PHP的支持preg_replace()
命名後向引用任何明確的:用preg_replace命名的反向引用
// should match, replace, and output: user/profile/foo
$string = 'user/foo';
echo preg_replace('#^user/(?P<id>[^/]+)$#Di', 'user/profile/(?P=id)', $string);
這是一個簡單的例子,但我想知道,如果這句法,(?P=name)
是根本不支持。語法問題,還是不存在的功能?
**感謝德米特里; **如果答案是*不*支持,那我就簡單地恢復到編號引用。 – Dan 2011-03-10 03:42:25
您可以使用帶有preg_replace_callback的命名匹配。 – Dimitry 2011-03-10 03:51:49
啊,從數組參數...很好知道,但不符合這裏的目的。該死,屁股疼得厲害。 – Dan 2011-03-10 03:53:31