工具類之剔除Html標籤 Java

如題:

 /**
     * 去除html格式,提取文字信息
     */
    public static String getContent(String content){
        if(StringUtil.isNull(content)){
            return "";
        }
        String txtcontent = setTextAreaHtml(content).replaceAll("</?[^>]+>", ""); //剔出<html>的標籤
        txtcontent = txtcontent.replaceAll("<a>\\s*|\t|\r|\n</a>", "");//去除字符串中的空格,回車,換行符,製表符
        return txtcontent;
    }

    public static String setTextAreaHtml(String content){
        return content.replaceAll("&lt;", "<").replaceAll("gt;", ">").replaceAll("&amp;", "&").replaceAll("&quot;", "\"").replaceAll("&apos;", "'").replaceAll("&nbsp;"," ");
    }
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章