【问题标题】:HTML entity decode javaHTML实体解码java
【发布时间】:2015-02-21 13:20:23
【问题描述】:

html_entity_decode($string, ENT_QUOTES, 'UTF-8'); 的 Java 等价物是什么? 在 PHP 中。 示例:

这是我的文字,

Mivan is an aluminium formwork system developed by a European construction company. In 1990, the Mivan Company Ltd. from Malaysia started manufacturing these formwork systems. Today, more than 30,000sqm of formwork from Mivan Co. Ltd. 

Advantages:

· More seismic resistance

· Increased durability

· Lesser number of joints and reduced leakages

· Higher carpet area

要求的格式是:

Mivan is an aluminium formwork system developed by a European construction company. In 1990, the Mivan Company Ltd. from Malaysia started manufacturing these formwork systems. Today, more than 30,000sqm of formwork from Mivan Co. Ltd. Advantages: · More seismic resistance · Increased durability · Lesser number of joints and reduced leakages .Higher carpet area.

在java中使用以下正则表达式删除空格/制表符/换行不起作用

comment=comment.replaceAll("\\s+", "");
comment=comment.replaceAll("\t\n\r", "");

【问题讨论】:

  • 这与 HTML 实体有什么关系?代码中是否包含任何 html 实体?
  • 这不是您在示例中提供的文本。您能否编辑您的问题并编写您遇到问题的 实际 文本、您真正期望的结果、您正在使用的代码以及该代码产生的您不喜欢的结果?顺便说一句,相关的PHP命令不是strip_tags而不是html_entity_decode吗?

标签: java php regex


【解决方案1】:

只需用一个空格替换一个或多个换行符。

String s ="Mivan is an aluminium formwork system developed by a European construction company. In 1990, the Mivan Company Ltd. from Malaysia started manufacturing these formwork systems. Today, more than 30,000sqm of formwork from Mivan Co. Ltd. \n" + 
            "\n" + 
            "Advantages:\n" + 
            "\n" + 
            "· More seismic resistance\n" + 
            "\n" + 
            "· Increased durability\n" + 
            "\n" + 
            "· Lesser number of joints and reduced leakages\n" + 
            "\n" + 
            "· Higher carpet area";
String comment = s.replaceAll("[\\n\\r]+", " ");
System.out.println(comment);

输出:

Mivan is an aluminium formwork system developed by a European construction company. In 1990, the Mivan Company Ltd. from Malaysia started manufacturing these formwork systems. Today, more than 30,000sqm of formwork from Mivan Co. Ltd.  Advantages: · More seismic resistance · Increased durability · Lesser number of joints and reduced leakages · Higher carpet area

【讨论】:

    【解决方案2】:

    您只需用一个空格替换所有空格:

    comment = comment.replaceAll("\\s+", " ");
    

    【讨论】:

      猜你喜欢
      • 2014-01-15
      • 2011-08-13
      • 2012-01-11
      • 1970-01-01
      • 1970-01-01
      • 2011-05-16
      相关资源
      最近更新 更多