BBCode Help improving script
Posted: Sun Mar 19, 2006 3:50 pm
Hi to everyone, i've searched the internet for bbcode 2 html script, and i've found this website with a great tutorial, i was searching a script that can workaround this litle bug.
Code: Select all
[quote]1a parte[quote]2a parte [/quote]3a parte[/quote][code]
When i use the following code:
[code]
<?php
$code_treated = "[quote]1a parte[quote]2a parte [/quote]3a parte[/quote]";
//Arrays for the bbCode replacements
$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');
$bbcode_replace = array(0 => '<b>$1</b>',
1 => '<i>$1</i>',
2 => '<u>$1</u>',
3 => '<table class="quote"><tr><td>Quote:</td></tr><tr><td class="quote_box">$1</td></tr></table>',
4 => '<table class="quote"><tr><td>$1 said:</td></tr><tr><td class="quote_box">$2</td></tr></table>',
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>');
ksort($bbcode_regex);
ksort($bbcode_replace);
//preg_replace to convert all remaining bbCode tags
$post_bbcode_treated = preg_replace($bbcode_regex, $bbcode_replace, $code_treated);
//Convert new lines to
$post_with_br = nl2br($post_bbcode_treated);
echo $post_with_br;
?>
[code]
This will result, that the first [quote] wil work with the first [/quote] tag and dismiss the other [quote] tag, but it should do this, the first [quote] with the last [/quote], and the second [quote] with the second [/quote].
Someona has some ideas how to fix this.
Thanks.
[color=#888888][size=85]Archived topic from Iceteks, old topic ID:4240, old post ID:34313[/size][/color]