文本转换为HTML文字编码

来源:互联网 发布:淘宝开店铺要多少钱 编辑:程序博客网 时间:2024/05/17 20:30
 /**
* 转换为HTML文字编码.<br>
*/
public static String htmlTextEncoder(String src) throws Exception
{
  if (src == null||src.equals(""))
  {
    return "";
  }
  String dst = src;
  dst = dst.replaceAll("<","&lt;");
  dst = dst.replaceAll(">","&rt;");
  dst = dst.replaceAll("/"","&quot;");
  dst = dst.replaceAll("'","&#039;");
  dst = dst.replaceAll(" ", "&nbsp;");
  dst = dst.replaceAll("/r/n", "<br>");
  dst = dst.replaceAll("/r", "<br>");
  dst = dst.replaceAll("/n", "<br>");
 
  return dst;
}