【发布时间】:2011-06-13 14:42:52
【问题描述】:
我在一些论坛帖子中使用了一些定制的标记/标记,我正在寻找一种体面的方法来处理它们(很可能使用正则表达式,我不太方便!)。
当我将论坛帖子呈现到屏幕上时,我想将文本中的定制标签转换为真实标签。帖子中的每个定制标签很可能有多个需要处理的实例。
以下是我需要处理的示例:
[URL=http://www.mysite.com]anchor text[/URL]
[URL=www.mysite.com]anchor text[/URL]
需要替换为:
<a href="http://www.mysite.com">anchor text</a>
[EMAIL=me@mysite.com]anchor text[/EMAIL]
需要替换为:
<a href="mailto:me@mysite.com">anchor text</a>
[IMG]http://www.mysite.com/image.jpg[/IMG]
[IMG]www.mysite.com/image.jpg[/IMG]
需要替换为:
<img src="http://www.mysite.com/image.jpg" />
[QUOTE=username]quoted text[/QUOTE]
需要替换为:
<div class="quote"><h3>Posted by: username</h3>quoted text</div>
【问题讨论】: