Your text string is wrong in 2nd case. Please try this:
<?php
$text = '[#ff0000] RedColor [/#ff0000] [#0000ff]BlueColor[/#0000ff]';
$text = preg_replace_callback('/\[(#[A-F,a-f,0-9]{6})\](.*?)\[(\/#[A-F,a-f,0-9]{6})\]/', function ($m) {
if("/".$m[1] == $m[3])
return '<font color="'.$m[1].'">'.$m[2].'</font>';
}, $text);
echo $text;
?>
Your text string should be like this :
$text = '[#ff0000] RedColor [/#ff0000] [#0000ff]BlueColor[/#0000ff]';
Tag for RedColor should be closed before starting of BlueColor. Hope it helps :)