This article describes how to use JS to convert HTML Escape characters // remove html tags
Function removeHtmlTab (tab) {return tab. replace (/<[^ <>] +?> /G, ''); // delete all HTML tags}
// Convert normal characters to escape characters
function html2Escape(sHtml) { return sHtml.replace(/[<>&"]/g,function(c){return {'<':'<','>':'>','&':'&','"':'"'}[c];});}
// Replace the Italian character with a normal character
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];});}
// Convert it to a space
function nbsp2Space(str) { var arrEntities = {'nbsp' : ' '}; return str.replace(/&(nbsp);/ig, function(all, t){return arrEntities[t]})}
// Press enter to convert to a br tag
function return2Br(str) { return str.replace(/\r?\n/g,"
");}
// Remove the start and end line breaks and convert them into two line breaks three times in a row
Function trimBr (str) {str = str. replace (/(\ s |) * \ r? \ N) {3,}/g, "\ r \ n"); // limit up to 2 line breaks str = str. replace (/^ (\ s |) * \ r? \ N) +/g, ''); // clear str = str. replace (/(\ s |) * \ r? \ N) + $/g, ''); // clear the end line feed return str ;}
// Combine multiple consecutive spaces into one space
function mergeSpace(str) { str=str.replace(/(\s| )+/g,' '); return str;}
The preceding figure shows how to use JavaScript to convert the details of HTML Escape characters. For more information, see other related articles in the first PHP community!