可能重複:
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