...

View Full Version : PHP to BBCode minor troubles



tribalmaniac
11-06-2006, 10:10 PM
I'm using the following code to convert BBCode to HTML:


function output_post ($post) {
$post_no_html = htmlspecialchars($post);
$post_abridged = chop($post_no_html);
$bbcode_regex = array(0 => '/\[b\](.+?)\[\/b\]/s',
1 => '/\[i\](.+?)\[\/i\]/s',
2 => '/\[u\](.+?)\[\/u\]/s',
3 => '/\[quote\](.+?)\[\/quote\]/s',
4 => '/\[quote\=(.+?)](.+?)\[\/quote\]/s',
5 => '/\[url\](.+?)\[\/url\]/s',
6 => '/\[url\=(.+?)\](.+?)\[\/url\]/s',
7 => '/\[img\](.+?)\[\/img\]/s',
8 => '/\[color\=(.+?)\](.+?)\[\/color\]/s',
9 => '/\[size\=(.+?)\](.+?)\[\/size\]/s',
10 => '/\[email\](.+?)\[\/email\]/s',
11 => '/\[email\=(.+?)](.+?)\[\/email\]/s',
12 => '/\[align\=(.+?)](.+?)\[\/align\]/s');

$bbcode_replace = array(0 => '<b>$1</b>',
1 => '<i>$1</i>',
2 => '<u>$1</u>',
3 => '<table border="0" CELLSPACING="0" CELLPADDING="0"><TR><TD CLASS="quote">$1</TD><TR></TABLE><p>',
4 => '<table border="0" CELLSPACING="0" CELLPADDING="0"><TR><TD CLASS="quote">$1 said:<br> $2</TD><TR></TABLE><p>',
5 => '<a href="$1">$1</a>',
6 => '<a href="$1">$2</a>',
7 => '<img src="$1" alt="User submitted image" title="User submitted image"/>',
8 => '<span style="color:$1">$2</span>',
9 => '<span style="font-size:$1">$2</span>',
10 => '<a href="mailto:$1">$1</A>',
11 => '<a href="mailto:$1">$1</A>',
12 => '<p align=$1>$2</p>');

ksort($bbcode_regex);
ksort($bbcode_replace);

//preg_replace to convert all remaining bbCode tags
$post_bbcode_treated = preg_replace($bbcode_regex, $bbcode_replace, $post_abridged);
//Convert new lines to <br />
$post_with_br = nl2br($post_bbcode_treated);


echo $post_with_br;
};

<here the table opens fine>
everything works perfectly except when a quote is inside another quote which looks like this:

<this is where the table starts, and it works fine>
Posted by User on November 06th, 2006 04:45 PM:
<the random unchanged bbcode quote tag here>
Posted by User on November 03rd, 2006 07:44 PM:
message 1
<here the table closes fine>

Message 2

<random unchanged closing bbcode tag here>

tribalmaniac
11-07-2006, 10:13 AM
anyone?

tribalmaniac
11-08-2006, 12:55 AM
The reason this is happening is because the script is searching for the first [ quote ] and the next [ /quote ] and because of this, any quotes that go inside and outside of that get ignored.

can anyone help me find a way round this?

iota
11-10-2006, 07:55 AM
My idea is to simply replace the
with <textarea id="quote"></textarea>, and
with <textarea id="code"></textarea>.

Apply CSS for formatting as you like.
For more details, download phpbb forum software from (http://prdownloads.sourceforge.net/phpbb/phpBB-2.0.21.zip?use_mirror=surfnet)
and learn their coversion coding.

I attached it for you.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum