HTML标签转义方法

//<,>转化成转义字符
function html_encode(str)
{
var s = "";
if (str.length == 0) return "";
s = str.replace(/&/g, "&gt;");
s = s.replace(/</g, "&lt;");
s = s.replace(/>/g, "&gt;");
s = s.replace(/ /g, "&nbsp;");
s = s.replace(/\'/g, "'");
s = s.replace(/\"/g, "&quot;");
s = s.replace(/\n/g, "<br>");
return s;
}
//转义字符反转义为标签符
function html_decode(str)
{
var s = "";
if (str.length == 0) return "";
s = str.replace(/&gt;/g, "&");
s = s.replace(/&lt;/g, "<");
s = s.replace(/&gt;/g, ">");
s = s.replace(/&nbsp;/g, " ");
s = s.replace(/'/g, "\'");
s = s.replace(/&quot;/g, "\"");
s = s.replace(/<br>/g, "\n");
return s;
}
上一篇:centos6.8 yum安装mysql 5.6 (完整)


下一篇:centos Apache、php、mysql默认安装路径