function nl2br_except_pre( $string )
{
    $string = nl2br($string);
    $pre2 = array();
    preg_match_all("/<pre[^>]*?>(.|\n)*?<\/pre>/", $string, $pre1);
    for ($x = 0; $x < count($pre1[0]); $x++) 
    {
        $pre2[$x] = str_replace( '<br />', '', $pre1[0][$x] );
        $pre1[0][$x] = "/".preg_quote($pre1[0][$x], "/")."/";
    }
    return preg_replace($pre1[0], $pre2, $string);
}