OK, at the moment I am using this regular expression-based function to process a BBcode-based message and translate it into HTML-encoding:
PHP Code:
function bbcodetranslate($string){
$string = nl2br(htmlspecialchars($string));
$patterns = array(
'`\[center\](.+?)\[/center\]`is',
'`\[b\](.+?)\[/b\]`is',
'`\[i\](.+?)\[/i\]`is',
'`\[u\](.+?)\[/u\]`is',
'`\[strike\](.+?)\[/strike\]`is',
'`\[color=(.+?)\](.+?)\[/color\]`is',
'`\[email\](.+?)\[/email\]`is',
'`\[img\](.+?)\[/img\]`is',
'`\[url=([a-z0-9]+://)([\w\-]+\.([\w\-]+\.)*[\w]+(:[0-9]+)?(/[^ \"\n\r\t<]*?)?)\](.*?)\[/url\]`si',
'`\[url\]([a-z0-9]+?://){1}([\w\-]+\.([\w\-]+\.)*[\w]+(:[0-9]+)?(/[^ \"\n\r\t<]*)?)\[/url\]`si',
'`\[url\]((www|ftp)\.([\w\-]+\.)*[\w]+(:[0-9]+)?(/[^ \"\n\r\t<]*?)?)\[/url\]`si',
'`\[flash=([0-9]+),([0-9]+)\](.+?)\[/flash\]`is',
'`\[quote\](.+?)\[/quote\]`is',
'`\[quote=(.+?)\](.+?)\[/quote\]`is',
'`\[indent](.+?)\[/indent\]`is',
'`\[size=([1-6]+)\](.+?)\[/size\]`is',
'`\[code\](.+?)\[/code\]`is',
'`\[html\](.+?)\[/html\]`is',
'`\[php\](.+?)\[/php\]`is',
'`\[news\](.+?)\[/news\]`is'
);
$replaces = array(
'<center>\\1</center>',
'<strong>\\1</strong>',
'<em>\\1</em>',
'<span style="border-bottom: 1px dotted">\\1</span>',
'<strike>\\1</strike>',
'\2',
'<a href="mailto:\1">\1</a>',
'<img src="\1" alt="" style="border:0px;" />',
'<a href="\1\2">\6</a>',
'<a href="\1\2">\1\2</a>',
'<a href="http://\1">\1</a>',
'<object width="\1" height="\2"><param name="movie" value="\3" /><embed src="\3" width="\1" height="\2"></embed></object>',
'<table style="margin:0px 5px;padding:5px;background-color:#F8F9F1;border:1px solid #CCCCCC;width:95%;" border="0" align="center" cellpadding="0" cellspacing="0"><tr><td><strong>Quote:</strong><em>\1</em></td></tr></table>',
'<table style="margin:0px 5px;padding:5px;background-color:#F8F9F1;border:1px solid #CCCCCC;width:95%;" border="0" align="center" cellpadding="0" cellspacing="0"><tr><td><strong>Quote from \1:</strong><br><em>\2</em></td></tr></table>',
'<pre>\\1</pre>',
'<h\1>\2</h\1>',
'<table class="code" border="0" align="center" cellpadding="0" cellspacing="0"><tr><td>\1</td></tr></table>',
'<table class="code" border="0" align="center" cellpadding="0" cellspacing="0"><tr><td>\1</td></tr></table>',
'<table class="code" border="0" align="center" cellpadding="0" cellspacing="0"><tr><td>\1</td></tr></table>',
'<table width="90%" align="center" border="0"><tr><td><p align="justify"><i>\1</i></td></tr></table>'
);
$string = preg_replace($patterns, $replaces , $string);
return $string;
}
Essentially, this means that when I use this string:
Code:
[url =http://blah.com]Blah[ /url] (Ignore the spaces)
I am given a url link. The thing is that this regular expression does not make use of quotation marks around the URL string itself.. something that is a newish function of Vbulletin v3.5.x. How would I amend my initial function to include translation for BOTH bbcodes with and without quotations? I've fiddled with this for a long time, and I'm pretty sure I must be missing something obvious...