【发布时间】:2011-06-19 08:34:41
【问题描述】:
直接跟进之前的question,我如何使用 PHP 将文本(如果可能的话,以及大括号)作为匹配项提取出来?
具体来说,我正在编写一个 Wordpress 插件,并希望重新格式化两个大括号之间的所有文本(准 wiki 标记)。
我已经按照我之前问过的另一个 question 中概述的步骤进行操作,并且 matching 部分正在工作 - 这是我需要帮助的 match。 p>
例子:
This is some {{text}} and I want to reformat the items inside the curly braces
期望的输出:
This is some *Text fancified* and I want to reformat the items inside the curly braces
我所拥有的(即不工作):
$content = preg_replace('#\b\{\{`.+`\}\}\b#', "<strong>$0</strong>", $content);
如果匹配包括大括号太难,我可以使用大括号作为偏移量进行匹配,然后也可以使用更简单的文本匹配函数删除“违规”大括号。
【问题讨论】:
标签: php regex plugins wordpress