【问题标题】:How do I find & replace a character between a text in 2 tags?如何在 2 个标签中的文本之间查找和替换字符?
【发布时间】:2016-08-05 20:15:32
【问题描述】:

通常我会在这个论坛上找到所有问题的答案,但现在我真的不知道该怎么办。

我从一个程序中得到一个 .xml 文件,我们使用这个 xml 文件在我们的网站上创建一篇文章/产品。 程序的输出是这样的:

<BigInfo>Description English: Spring washer&lt;br&gt;Descrizione Italiano: Rosetta</BigInfo>

我想要这样的输出:

<BigInfo><![CDATA[Description English: Spring washer<br>Descrizione Italiano: Rosetta]]></BigInfo>

我已经写了一个脚本来替换 &lt;BigInfo&gt; 代表 &lt;BigInfo&gt;&lt;![CDATA[&lt;/BigInfo&gt; 代表 ]]&gt;&lt;/BigInfo&gt;

但现在我需要将 &amp;lt;&amp;gt; 替换为 BigInfo 标记之间的 &lt;

希望大家能帮帮我!

亲切的问候,

科恩·德哈恩

【问题讨论】:

  • 从 XML 的角度来看,这两种格式是等价的。

标签: html xml replace words


【解决方案1】:

您的脚本语言是什么? PHP有例如:

http://php.net/manual/en/function.html-entity-decode.php

这正是你想要的:

<?php
$orig = "I'll \"walk\" the <b>dog</b> now";

$a = htmlentities($orig);

$b = html_entity_decode($a);

echo $a; // I'll &quot;walk&quot; the &lt;b&gt;dog&lt;/b&gt; now

echo $b; // I'll "walk" the <b>dog</b> now
?>

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2021-10-14
  • 2016-03-31
  • 1970-01-01
  • 1970-01-01
  • 2013-07-26
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多