可能重复:
Is there a PHP function that can escape regex patterns before they are applied?摆脱使用字符串中的正则表达式
我想使用存储在一个变量正则表达式的字符串。 (PHP中)转义字符串以用于(PCRE)正则表达式的最佳方式是什么?
例如,
$text = 'm/z'; // this is the text I want to use as part of my regular expression
$text_regexp = '#' . $text . '#i'; // this is my regular expression
还会送
$text_regexp = '#m/z#i';
但我想下面的正则表达式:
$text_regexp = '#m\/z#i';
这是一个人为的例子,但我想说明这一点简单。
谢谢你的快速回答。 – Tomba 2011-02-08 17:43:58
不客气。乐意效劳。 – webbiedave 2011-02-08 17:45:26