honestly, you shouldn't be looking at how to do this, but rather WHY you are doing it...
this seems totally unneccessary to me. i'm guessing this is for a forum or something that you want to allow minimal html. if so, just pass the text through a function like this:
function format_output($output) {
$output = htmlspecialchars(stripslashes($output));
$output = str_replace('[big]', '<big>', $output);
$output = str_replace('[/big]', '</big>', $output);
$output = str_replace('[small]', '<small>', $output);
$output = str_replace('[/small]', '</small>', $output);
$output = str_replace('[ul]', '<ul>', $output);
$output = str_replace('[/ul]', '</ul>', $output);
$output = str_replace('[ol]', '<ol>', $output);
$output = str_replace('[/ol]', '</ol>', $output);
$output = str_replace('[li]', '<li>', $output);
$output = str_replace('[/li]', '</li>', $output);
$output = str_replace('[p]', '<p>', $output);
$output = str_replace('', '<b>', $output);
$output = str_replace('', '</b>', $output);
$output = str_replace('', '<i>', $output);
$output = str_replace('', '</i>', $output);
$output = str_replace('[pre]', '<pre>', $output);
$output = str_replace('[/pre]', '</pre>', $output);
$output = str_replace('[indent]', '<blockquote>', $output);
$output = str_replace('[/indent]', '</blockquote>', $output);
$output = str_replace('[line]', '<hr />', $output);
$output = ereg_replace('[anchor="([[:graph:]]+)"]', '<a name="\1"></a>', $output);
$output = str_replace('[link="javascript', '[link=" javascript', $output);
$output = ereg_replace('[link="([[:graph:]]+)"]', '<a href="\1">', $output);
$output = str_replace('[/link]', '</a>', $output);
$output = eregi_replace(" "," ",$output);
return nl2br($output);
}