'\[b\]', 'endtag' => '\[/b\]',
'starthtml' => '', 'endhtml' => '',
'children' => array(&$b, &$u, &$i, &$color, &$img, &$url1, &$url2));
$u = array('starttag' => '\[u\]', 'endtag' => '\[/u\]',
'starthtml' => '', 'endhtml' => '',
'children' => array(&$b, &$u, &$i, &$color, &$img, &$url1, &$url2));
$i = array('starttag' => '\[i\]', 'endtag' => '\[/i\]',
'starthtml' => '', 'endhtml' => '',
'children' => array(&$b, &$u, &$i, &$color, &$img, &$url1, &$url2));
$color = array('starttag' => '\[color=([A-Za-z]+|#(?:[\dA-Fa-f]{3}){1,2}?|rgb\((?:100%|\d?\d%),(?:100%|\d?\d%),(?:100%|\d?\d%)\)|rgb\((?:1?\d?\d|2(?:[0-4]\d|5[0-5])),(?:1?\d?\d|2(?:[0-4]\d|5[0-5])),(?:1?\d?\d|2(?:[0-4]\d|5[0-5]))\))\]', 'endtag' => '\[/color\]',
'starthtml' => '', 'endhtml' => '',
'children' => array(&$b, &$u, &$i, &$color, &$img, &$url1, &$url2));
$img = array('starttag' => '\[img\]([^\[]*)\[/img\]', 'starthtml' => '');
$url1 = array('starttag' => '\[url\]([^\[]*)\[/url\]', 'starthtml' => '$1)');
$url2 = array('starttag' => '\[url=([^\]]*)\]', 'endtag' => '\[/url\]',
'starthtml' => '', 'endhtml' => '',
'children' => array(&$b, &$u, &$i, &$color, &$img, &$url1, &$url2));
$list1 = array('starttag' => '\[list\]\s*\[\*\]', 'endtag' => '\[/list\]',
'starthtml' => '
',
'children' => array(&$b, &$u, &$i, &$color, &$img, &$url1, &$url2, &$list1, &$list2, &$list3, &$star));
$list2 = array('starttag' => '\[list=1\]\s*\[\*\]', 'endtag' => '\[/list\]',
'starthtml' => '- ', 'endhtml' => '
',
'children' => array(&$b, &$u, &$i, &$color, &$img, &$url1, &$url2, &$list1, &$list2, &$list3, &$star));
$list3 = array('starttag' => '\[list=a\]\s*\[\*\]', 'endtag' => '\[/list\]',
'starthtml' => '- ', 'endhtml' => '
',
'children' => array(&$b, &$u, &$i, &$color, &$img, &$url1, &$url2, &$list1, &$list2, &$list3, &$star));
$star = array('starttag' => '\[\*\]', 'starthtml' => '');
$this->codes = array(&$b, &$u, &$i, &$color, &$img, &$url1, &$url2, &$list1, &$list2, &$list3);
}
function Parse($data) {
$data = htmlentities($data);
$out = '';
$tags = array();
while(true) {
if($tags && preg_match('(^([^\[]*)' . $tags[count($tags)-1]['endtag'] . '(.*)$)s', $data, $match)) {
$out .= $match[1] . $tags[count($tags)-1]['endhtml'];
$data = $match[count($match)-1];
array_pop($tags);
continue;
}
if($tags) $codes = &$tags[count($tags)-1]['children'];
else $codes = &$this->codes;
$found = false;
foreach($codes as $code) {
if(preg_match('(^([^\[]*)(' . $code['starttag'] . ')(.*)$)s', $data, $match)) {
$out .= $match[1];
$out .= preg_replace('(^' . $code['starttag'] . '$)s', $code['starthtml'], $match[2]);
$data = $match[count($match)-1];
if($code['endtag'])
array_push($tags, $code);
$found = true;
break;
}
}
if($found) continue;
if(!preg_match('(^([^\[]*\[)(.*)$)s', $data, $match)) break;
$out .= $match[1];
$data = $match[2];
}
$out .= $data;
while($tag = array_pop($tags))
$out .= $tag['endhtml'];
return strtr($out, array("\n" => '
', "\r" => ''));
}
}
$GLOBALS['bbcode'] = new BBCode;
?>