0
我想開發一個基本的模板引擎,所以我必須使用preg_replace這麼多。我有一個問題關於主題如下:Php preg_replace,正則表達式模式不匹配
$subject = "{%content%} %content%";
$pattern = '/matched_regex/';
$replace = 'OK';
echo preg_replace($pattern,$replace,$subject);
和輸出必須是這樣的:
{%content%} OK
換句話說
它將與%content%
正好匹配我應該怎麼做正則表達式模式?
我已經試過這 $模式=「/ [^ {] \ S *(。?*)\ S *%[^}] /'; – 2015-03-02 21:31:32
and this $ pattern ='/{{0}?%\s*(.*?)\s*%}{0}/'; – 2015-03-02 21:35:09