/**
* 转换为HTML文字编码.<br>
*/
public static String htmlTextEncoder(String src) throws Exception
{
if (src == null||src.equals(""))
{
return "";
}
String dst = src;
dst = dst.replaceAll("<","<");
dst = dst.replaceAll(">","&rt;");
dst = dst.replaceAll("/"",""");
dst = dst.replaceAll("'","'");
dst = dst.replaceAll(" ", " ");
dst = dst.replaceAll("/r/n", "<br>");
dst = dst.replaceAll("/r", "<br>");
dst = dst.replaceAll("/n", "<br>");
return dst;
}
* 转换为HTML文字编码.<br>
*/
public static String htmlTextEncoder(String src) throws Exception
{
if (src == null||src.equals(""))
{
return "";
}
String dst = src;
dst = dst.replaceAll("<","<");
dst = dst.replaceAll(">","&rt;");
dst = dst.replaceAll("/"",""");
dst = dst.replaceAll("'","'");
dst = dst.replaceAll(" ", " ");
dst = dst.replaceAll("/r/n", "<br>");
dst = dst.replaceAll("/r", "<br>");
dst = dst.replaceAll("/n", "<br>");
return dst;
}
本文介绍了一种将普通文本转换为适用于HTML显示的方法,通过替换特殊字符为HTML实体来确保文本能在网页上正确显示,同时支持自动换行。
1701

被折叠的 条评论
为什么被折叠?



