标签:
function html_encode(str)
{ var s = ""; if (str.length == 0) return ""; s = str.replace(/&/g, "&"); s = s.replace(/</g, "<"); s = s.replace(/>/g, ">"); s = s.replace(/ /g, " "); s = s.replace(/\‘/g, "'"); s = s.replace(/\"/g, """); s = s.replace(/\n/g, "<br/>"); return s; } function html_decode(str) { var s = ""; if (str.length == 0) return ""; s = str.replace(/&/g, "&"); s = s.replace(/</g, "<"); s = s.replace(/>/g, ">"); s = s.replace(/ /g, " "); s = s.replace(/'/g, "\‘"); s = s.replace(/"/g, "\""); s = s.replace(/<br\/>/g, "\n"); return s; } function removeHtmlTab(tab) { return tab.replace(/<[^<>]+?>/g,‘‘);//删除所有HTML标签 } function html2Escape(sHtml) { return sHtml.replace(/[<>&"]/g,function(c){return {‘<‘:‘<‘,‘>‘:‘>‘,‘&‘:‘&‘,‘"‘:‘"‘}[c];}); } function escape2Html(str) { var arrEntities={‘lt‘:‘<‘,‘gt‘:‘>‘,‘nbsp‘:‘ ‘,‘amp‘:‘&‘,‘quot‘:‘"‘}; return str.replace(/&(lt|gt|nbsp|amp|quot);/ig,function(all,t){return arrEntities[t];}); } function nbsp2Space(str) { var arrEntities = {‘nbsp‘ : ‘ ‘}; return str.replace(/&(nbsp);/ig, function(all, t){return arrEntities[t]}) } function return2Br(str) { return str.replace(/\r?\n/g,"<br />"); } function trimBr(str) { str=str.replace(/((\s| )*\r?\n){3,}/g,"\r\n\r\n");//限制最多2次换行 str=str.replace(/^((\s| )*\r?\n)+/g,‘‘);//清除开头换行 str=str.replace(/((\s| )*\r?\n)+$/g,‘‘);//清除结尾换行 return str; } function mergeSpace(str) { str=str.replace(/(\s| )+/g,‘ ‘); return str; }
var str="<script type=‘text/javascript‘ >jjj</script>kkk " ;str=str.replace(/</g,‘<‘); str=str.replace(/>/g,‘>‘); var reg=/<script[^>]*>(.|\n)*?(?=<\/script>)<\/script>/gi; alert(str.replace(reg,‘‘));
|
标签:
原文地址:http://www.cnblogs.com/shenggen/p/4970308.html