PHP:
function htmltocode( $content ){
$content = str_replace(" "," ",$content);
$content = str_replace("\n","<br>",$content);
return $content;
}JS:
String.prototype.replaceAll = function(s1,s2){
return this.replace(new RegExp(s1,"gm"),s2);
}
str = str.replaceAll("\n", "<br/>");如果替换回来只要反过来写就行了。