简单的php ubb转换代码
[b]test[/b] [url=http://blah.com]blah[/url]
will become:
<strong>test</strong> <a href="http://blah.com" target="_blank" rel="noopener">blah</a>
php
function ubbcode($posting) { $posting=eregi_replace("\[img\]([^\[]+)\[/img\]","<img src=\"\\1\" border=\"0\">",$posting); $posting=eregi_replace("\[email\]([^\[]+)\[/email\]","<a href=\"mailto:\\1\">\\1</a>",$posting); $posting=eregi_replace("\[email=([^\[]+)\]([^\[]+)\[/email\]","<a href=\"mailto:\\1\">\\2</a>",$posting); $posting=eregi_replace("\[url=([^\[]+)\]([^\[]+)\[/url\]","<a href=\"\\1\" target=\"_blank\">\\2</a>",$posting); $posting=eregi_replace("\[url\]([^\[]+)\[/url\]","<a href=\"\\1\" target=\"_blank\">\\1</a>",$posting); $posting=eregi_replace("\[b\]","<strong>",$posting); $posting=eregi_replace("\[/b\]","</strong>",$posting); $posting=eregi_replace("\[u\]","<u>",$posting); $posting=eregi_replace("\[/u\]","</u>",$posting); $posting=eregi_replace("\[i\]","<em>",$posting); $posting=eregi_replace("\[/i\]","</em>",$posting); return $posting; }