Devi usare le RegEx, ti passo una funzione che feci tanto tempo fà:
Codice PHP:
function parsebb($post){
$message=$post;
$bb = array();
//Bold
$bb[0]['regex'] = "#\[b\](.*?)\[/b\]#si";
$bb[0]['replace'] = "[b]$1[/b]";
//Center
$bb[1]['regex'] = "#\[center\](.*?)\[/center\]#si";
$bb[1]['replace'] = "<center>$1</center>";
//Underline
$bb[2]['regex'] = "#\[u\](.*?)\[/u\]#si";
$bb[2]['replace'] = "<u>$1</u>";
//Italic
$bb[3]['regex'] = "#\[i\](.*?)\[/i\]#si";
$bb[3]['replace'] = "[i]$1[/i]";
//Color
$bb[4]['regex'] = "#\[color=([a-zA-Z]*|\#?[0-9a-fA-F]{6})](.*?)\[/color\]#si";
$bb[4]['replace'] = '<font color="$1">$2</font>';
//URL Complex
$bb[5]['regex'] = "#\[url=(.*?)](.*?)\[/url\]#si";
$bb[5]['replace'] = '[url="$1"]$2[/url]';
//URL Simple
$bb[6]['regex'] = "#\[url\](.*?)\[/url\]#si";
$bb[6]['replace'] = '[url="$1"]$1[/url]';
//Quote
$bb[7]['regex'] = "#\[quote\](.*?)\[/quote\]#si";
$bb[7]['replace'] = '<blockquote>$1</blockquote>';
//Code
$bb[8]['regex'] = "#\[code\](.*?)\[/code\]#si";
$bb[8]['replace'] = '<code>$1</code>';
//Img
$bb[9]['regex'] = "#\[img\](.*?)\[/img\]#si";
$bb[9]['replace'] = '[img]$1[/img]';
foreach($bb as $tato){
$message = preg_replace($tato['regex'],$tato['replace'],$message);
}
return stripslashes($message);
}
Ti consiglio di approfondire le RegEx