php和javascript替换回车空格函数

PHP1744浏览0条评论函数JavaScriptPHP

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/>");

如果替换回来只要反过来写就行了。

本文地址:http://wuheng.net/blog_84.html 转载请注明出处

分享到: