本文介绍了将特殊字符转换为HTML编码字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将所有特殊字符转换为HTML编码字符.我发现许多与二手HttpUtility.HtmlEncode();有关的帖子,但只会转换某些特殊字符,例如"&", "<", ">".

I want to converter all special characters into Html encoded characters.I found many post related to used HttpUtility.HtmlEncode(); ,but it's only convert some of special characters like "&", "<", ">".

是否可以使用C#或javascript将所有特殊字符(如"š","Ø","þ","›","Ù")转换为HTML实体?

Is there any way to convert all special character like "š","Ø","þ","›","Ù" into Html entity using C# or javascript?

推荐答案

Microsoft AntiXss库可以完成此操作;

string p = Microsoft.Security.Application.Encoder.HtmlEncode("aaa <b>sdf</b> š,Ø,þ,›,Ù", true);
Response.Write(p);

对于

aaa &lt;b&gt;sdf&lt;/b&gt; &scaron;,&Oslash;,&thorn;,&rsaquo;,&Ugrave;

这篇关于将特殊字符转换为HTML编码字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 12:19
查看更多