It is easy if you know regular expressions. Here is the code you need: (Assuming that the code between the tags will be a string that doesn't contain whitespace.
PHP Code:
preg_match_all("#\[bbcode\](\w+)\[\/bbcode\]#i",$template,$matches);
foreach($matches[0] as $value){
//$value contains the each instance of entire blocks matched "[bbcode]stringWithoutWhitespace[/bbcode]"
}
foreach($matches[1] as $value){
//$value contains each instance of only stringWithoutWhitespace between the tags.
}
I hope this is helpful.