leave this line out
$string = str_replace("\n", "<br />", $string);
the function [man]nl2br/man takes care of this already.
you can either use my method,
function string1($string){
return nl2br(htmlspecialchars($string));
}
or the one eves suggested, like this:
function string1($string){
return nl2br(strip_tags($string));
}
the difference will be, that my version will still display the html tags, but not as tags but as encoded html (like < as <, etc.). eves version will get rid of all html tags altogether, unless you want to allow some specific ones. check [man]strip_tags/man for more info.