// BBcode Parsing
//
function parseBB($string, $rawlinebreak = 0){
//REPLACE BASIC "Start And End" TAGS
//
$basicsrc = array('/\[b\]/i','/\[\/b\]/i','/\[i\]/i','/\[\/i\]/i','/\[u\]/i','/\[\/u\]/i','/\[center\]/i','/\[\/center\]/i','/\[s\]/i','/\[\/s\]/i','/\[indent\]/i','/\[\/indent\]/i');
$basicrpl = array('','','','','','','
','','','','','
');
//This block will append for any unclosed elements.
for($i = 0; $i < sizeof($basicsrc)-1; $i++){
$matches_open = preg_match_all($basicsrc[$i], $string, $temp);
$i++;
$matches_close = preg_match_all($basicsrc[$i], $string, $temp);
for($j = 0; $j < ($matches_open - $matches_close); $j++){
$string .= $basicrpl[$i];
}
}
$string = preg_replace($basicsrc, $basicrpl, $string);
if(!$rawlinebreak){
$string = preg_replace('/\n/',"
",$string);
} else {
$string = preg_replace('/\n/',"",$string);
}
//REPLACE [tag]content[/tag]
//
$simple_replace = array('img'=>'
');
foreach($simple_replace as $tag=>$html){
$markup = array();
preg_match_all('/\['.$tag.'\](.+?)\[\/'.$tag.'\]/i', $string, $matches, PREG_PATTERN_ORDER);
for($i = 0; $i < sizeof($matches[0]); $i++){
$markup[] = str_replace("{{CONTENT}}",$matches[1][$i],$html);
}
$string = str_replace($matches[0],$markup, $string);
}
//Handle [tag=value]content[/tag]
//
$complex_replace = array(
'url' => '{{CONTENT}}',
'color' => '{{CONTENT}}',
'size' => '{{CONTENT}}'
);
foreach($complex_replace as $tag=>$html){
$markup = array();
preg_match_all('/\['.$tag.'=(.+?)\](.+?)\[\/'.$tag.'\]/i', $string, $matches, PREG_PATTERN_ORDER);
//print_r($matches);
for($i = 0; $i < sizeof($matches[0]); $i++){
$tempval = str_replace("{{CONTENT}}",$matches[2][$i],$html);
$markup[] = str_replace("{{VALUE}}",$matches[1][$i],$tempval);
}
$string = str_replace($matches[0],$markup, $string);
}
return $string;
}