a25495813 发表于 2024-9-8 18:05:19

过滤HTML标签 该怎么写?

java 有个方法过滤html标签,但是火山里面该怎么写

有例子么?

这个还挺实用的
public static String stripHtml(String content) {//过滤HTML标签
      // <p>段落替换为换行
      content = content.replaceAll("<p .*?>", "\r\n");
      // <br><br/>替换为换行
      content = content.replaceAll("<br\\s*/?>", "\r\n");
      // 去掉其它的<>之间的东西
      content = content.replaceAll("\\<.*?>", "");
      // 还原HTML
      // content = HTMLDecoder.decode(content);
      //“"
      content = content.replaceAll("&.dquo;", "\"");
      content = content.replaceAll(" ", " ");
      return content;
    }有没有大佬翻译一下

创世魂 发表于 2024-9-8 19:07:55

replaceAll   是正则文本替换

a25495813 发表于 2024-9-8 22:41:45

创世魂 发表于 2024-9-8 19:07
replaceAll   是正则文本替换

大佬能帮忙翻译一下么

创世魂 发表于 2024-9-8 23:29:24

a25495813 发表于 2024-9-8 22:41
大佬能帮忙翻译一下么
就是正则文本替换 这个方法啊。
replaceAll =正则文本替换。你就把java里面所有   replaceAll 换成正则文本替换就行了。

HTMLDecoder.decode这个没有。

a25495813 发表于 2024-9-8 23:34:13

创世魂 发表于 2024-9-8 23:29
就是正则文本替换 这个方法啊。
replaceAll =正则文本替换。你就把java里面所有   replaceAll 换成正 ...

哦哦我试试
页: [1]
查看完整版本: 过滤HTML标签 该怎么写?