I was just wondering if anyone knows of the simplest way to parse BB Code from Xenforo's post table in the correct fashion on an external page located on the same webserver.
(Complete php novice here)
Currently I am using the following code to query the relevant info.
and then using
To parse it, and then displaying it with a while loop.
The regex does not want to parse the nested BBcode elements, and I haven't found a way to call xenforo's parser to the external page yet, any help in this matter could be appreciated.
This is the page, showing what is currently doing. For comparison here is the xenporta link.
Thanks in advanced.
(Complete php novice here)
Currently I am using the following code to query the relevant info.
PHP:
$query="SELECT xf_post.thread_id, xf_thread.title, xf_thread.reply_count, xf_thread.view_count, xf_post.username, xf_post.user_id, xf_post.post_date, xf_post.message FROM xf_thread, xf_post WHERE xf_thread.first_post_id = xf_post.post_id AND xf_thread.node_id = '10' ORDER BY xf_post.post_date LIMIT 4";
$result = mysql_query($query) or die(mysql_error());
and then using
PHP:
function bb($content) {
$search = array (
'#\[CENTER\](.+)\[\/CENTER\]#iUs',
'#\[IMG\](.+)\[\/IMG\]#iUs',
'#\[B\](.+)\[\/B\]#iUs',
'#\[COLOR=(.+)\](.+)\[\/COLOR\]#iUs',
'#\[SIZE=(.+)\](.+)\[\/SIZE\]#iUs',
'#\[URL\](.+)\[\/URL\]#iUs',
'#\[URL=(.+)\](.+)\[\/URL\]#iUs',
'#\[FONT=(.+)\](.+)\[\/FONT\]#is',
'#\[EMAIL=(.+)\](.+)\[\/EMAIL\]#iUs',
);
$replace = array (
'<span style="text-align: center;">$1</span>',
'<img style="max-width: 95%;" src="$1">',
'<b>$1</b>',
'<span style="color: $1;">$2</span>',
'<span style="font-size: $1;">$2</span>',
'<a href="$1">$1</a>',
'<a href="$1">$2</a>',
'<span style="font-family: $1;">$2</span>',
'<a href="mailto:$1">$2</a>'
);
$newtext = preg_replace($search, $replace, $content);
$newtext = nl2br($newtext);//second pass
$newtext = preg_replace('#<br />(\s*<br />)+#', '<br />', $newtext);
return $newtext;
}
To parse it, and then displaying it with a while loop.
The regex does not want to parse the nested BBcode elements, and I haven't found a way to call xenforo's parser to the external page yet, any help in this matter could be appreciated.
This is the page, showing what is currently doing. For comparison here is the xenporta link.
Thanks in advanced.