使用Regexp或php函数替换标记之间字符的所有实例


Replace all instances of a character between tags using Regexp or php functions

好吧,老实说,我对我在说什么只有一个模糊的想法。所以我有这个标记规则

$config['markup'][] = array("/'[tag'](.+?)'['/tag']/m", "<span style='"font-weight:    bold'">$1</span>");

格式化[标签][/标签]中的文本

如何将字符x替换为字符y,但只能在[tag][/tag]内?

我想这可以用php函数完成,因为有这个示例代码

// Highlight PHP code wrapped in <code> tags (PHP 5.3+)
// $config['markup'][] = array(
//  '/^&lt;code&gt;(.+)&lt;'/code&gt;/ms',
//  function($matches) {
//      return highlight_string(html_entity_decode($matches[1]), true);
//  }
// );

但我无法把它变成我想要的。我不是程序员。

你的想法太复杂了。你所需要做的就是:

$replaced_text=preg_replace("/''[tag''](.+?)''[''/tag'']/m", "<span style='"font-weight: bold'">$1</span>", $original_text);