⼩程序转义html标签,wxDiscode-⼩程序特殊字符转义符
转化⼯具类
问题
在⼤部分html或者其它富⽂本在保存到后台中,为了安全起见需要将⼀些特殊字符进⾏转义
但是,请求回来的信息中包涵着这些转义过后的字符,⽽⼩程序是不能够直接进⾏反转义成为html特殊字符,所以需要将字符串特殊字符替换后才能恢复
作⽤
⽤于转义html中的特殊字符
解析类型
HTML ⽀持的数学符号
HTML ⽀持的希腊字母
HTML ⽀持的其他实体
代码很简单,复制粘贴太难,所以提供给⼤家以便使⽤,欢迎补充修改
// HTML ⽀持的数学符号
function strNumDiscode(str){
str = place(/∀/g, '∀');
str = place(/∂/g, '∂');
str = place(/&exists;/g, '∃');
str = place(/∅/g, '∅');
str = place(/∇/g, '∇');
str = place(/∈/g, '∈');
str = place(/∉/g, '∉');
str = place(/∋/g, '∋');
str = place(/∏/g, '∏');
str = place(/∑/g, '∑');
str = place(/−/g, '−');
str = place(/∗/g, '∗');
str = place(/√/g, '√');
str = place(/∝/g, '∝');
str = place(/∞/g, '∞');
str = place(/∠/g, '∠');
str = place(/∧/g, '∧');
str = place(/∼/g, '∼');
str = place(/≅/g, '≅');
str = place(/≈/g, '≈');
str = place(/≠/g, '≠');
str = place(/≤/g, '≤');
str = place(/≥/g, '≥');
str = place(/⊂/g, '⊂');
str = place(/⊃/g, '⊃');
str = place(/⊄/g, '⊄');
str = place(/⊆/g, '⊆');
str = place(/⊇/g, '⊇');
str = place(/⊕/g, '⊕');
str = place(/⊗/g, '⊗');
str = place(/⊥/g, '⊥');
str = place(/⋅/g, '⋅');
return str;
}
//HTML ⽀持的希腊字母
function strGreeceDiscode(str){ str = place(/Α/g, 'Α');
str = place(/Β/g, 'Β');
str = place(/Γ/g, 'Γ');
str = place(/Δ/g, 'Δ');
str = place(/Ε/g, 'Ε');
str = place(/Ζ/g, 'Ζ');
str = place(/Η/g, 'Η');代码转换
str = place(/Θ/g, 'Θ');
str = place(/Ι/g, 'Ι');
str = place(/Κ/g, 'Κ');
str = place(/Π/g, 'Π'); str = place(/Ρ/g, 'Ρ'); str = place(/Σ/g, 'Σ'); str = place(/Τ/g, 'Τ'); str = place(/Υ/g, 'Υ'); str = place(/Φ/g, 'Φ'); str = place(/Χ/g, 'Χ'); str = place(/Ψ/g, 'Ψ'); str = place(/Ω/g, 'Ω'); str = place(/α/g, 'α'); str = place(/β/g, 'β'); str = place(/γ/g, 'γ'); str = place(/δ/g, 'δ'); str = place(/ε/g, 'ε'); str = place(/ζ/g, 'ζ'); str = place(/η/g, 'η'); str = place(/θ/g, 'θ'); str = place(/ι/g, 'ι'); str = place(/κ/g, 'κ'); str = place(/λ/g, 'λ'); str = place(/μ/g, 'μ'); str = place(/ν/g, 'ν'); str = place(/ξ/g, 'ξ'); str = place(/ο/g, 'ο'); str = place(/π/g, 'π'); str = place(/ρ/g, 'ρ'); str = place(/ς/g, 'ς'); str = place(/σ/g, 'σ'); str = place(/τ/g, 'τ');
str = place(/ϑ/g, 'ϑ');
str = place(/ϒ/g, 'ϒ');
str = place(/ϖ/g, 'ϖ');
str = place(/·/g, '·');
return str;
}
//
function strcharacterDiscode(str){ // 加⼊常⽤解析
str = place(/ /g, ' ');
str = place(/"/g, "'");
str = place(/&/g, '&');
// str = place(/</g, '‹');
// str = place(/>/g, '›');
str = place(/</g, '');
str = place(/·/g, '·');
return str;
}
// HTML ⽀持的其他实体
function strOtherDiscode(str){
str = place(/Œ/g, 'Œ');
str = place(/œ/g, 'œ');
str = place(/Š/g, 'Š');
str = place(/š/g, 'š');
str = place(/Ÿ/g, 'Ÿ');
str = place(/ƒ/g, 'ƒ');
str = place(/ˆ/g, 'ˆ');
str = place(/˜/g, '˜');
str = place(/ /g, '');
str = place(//g, '');
str = place(//g, '');
str = place(//g, '');
str = place(//g, '');
str = place(/–/g, '–'); str = place(/—/g, '—'); str = place(/‘/g, '‘'); str = place(/’/g, '’'); str = place(/‚/g, '‚');
str = place(/“/g, '“'); str = place(/”/g, '”'); str = place(/…/g, '…'); str = place(/†/g, '†'); str = place(/‡/g, '‡'); str = place(/·/g, '·'); str = place(/…/g, '…'); str = place(/‰/
g, '‰'); str = place(/′/g, '′'); str = place(/″/g, '″'); str = place(/‹/g, '‹'); str = place(/›/g, '›'); str = place(/‾/g, '‾'); str = place(/€/g, '€'); str = place(/™/g, '™'); str = place(/←/g, '←'); str = place(/↑/g, '↑'); str = place(/→/g, '→'); str = place(/↓/g, '↓'); str = place(/↔/g, '↔'); str = place(/↵/g, '↵'); str = place(/⌈/g, '⌈'); str = place(/⌉/g, '⌉');
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论