【问题标题】:getting html tags from xml and echoing in php?从 xml 获取 html 标签并在 php 中回显?
【发布时间】:2012-03-18 17:30:22
【问题描述】:

我正在尝试将来自 xml 的结果回显到我的 html 代码表单 expedia 中。但是我遇到了一个问题。里面的文字有点乱:

<areaInformation>
Distances are calculated in a straight line from the property&apos;s location to the point of interest or attraction, and may not reflect actual travel distance. &lt;br /&gt;&lt;br /&gt; Distances are displayed to the nearest 0.1 mile and kilometre. &lt;p&gt;La Isla Shopping Mall - 0.5 km / 0.3 mi &lt;br /&gt;Yamil Lu&apos;um - 0.5 km / 0.3 mi &lt;br /&gt;Acuario Interactivo - 0.6 km / 0.3 mi &lt;br /&gt;Luxury Avenue - 1.5 km / 0.9 mi &lt;br /&gt;Cancun Golf Club at Pok Ta Pok - 2.2 km / 1.3 mi &lt;br /&gt;Nautilus Diving and Training Center - 2.6 km / 1.6 mi &lt;br /&gt;Cancun Convention Center - 2.8 km / 1.7 mi &lt;br /&gt;Plaza Caracol - 2.8 km / 1.8 mi &lt;br /&gt;Playa Tortuga - 3.1 km / 1.9 mi &lt;br /&gt;Aquaworld - 3.6 km / 2.2 mi &lt;br /&gt;Playa Langosta - 4.1 km / 2.6 mi &lt;br /&gt;Museo de Arte Popular Mexicano - 4.6 km / 2.9 mi &lt;br /&gt;Playa Linda - 5 km / 3.1 mi &lt;br /&gt;Playa Delfines - 6.1 km / 3.8 mi &lt;br /&gt;El Rey Ruins - 6.2 km / 3.8 mi &lt;br /&gt;&lt;/p&gt;&lt;p&gt;The preferred airport for ME Cancun - Complete ME All Inclusive is Cancun, Quintana Roo (CUN-Cancun Intl.) - 14.3 km / 8.9 mi. &lt;/p&gt;
</areaInformation>

我在 php 中回显它:

<div id="hotelInfo"><?php echo $areaInfo ?></div>

当然,我在浏览器窗口中得到了这个:

Distances are calculated in a straight line from the property's location to the point of interest or attraction, and may not reflect actual travel distance. <br /><br /> Distances are displayed to the nearest 0.1 mile and kilometre. <p>La Isla Shopping Mall - 0.5 km / 0.3 mi <br />Yamil Lu'um - 0.5 km / 0.3 mi <br />Acuario Interac

等等

我该如何解决这个问题???任何帮助将不胜感激!谢谢! 我希望它输出没有任何 html 标签的普通文本。

【问题讨论】:

  • 编辑 XML 文件并使用
  • 究竟是什么问题?您给我们输入和错误输出,好的,但也给我们期望的输出以帮助我们了解您的需求。
  • 我希望它输出没有任何html标签的普通文本。

标签: php html xml


【解决方案1】:

您正在寻找解码该字符串中的htmlspecialchars 编码:

<div id="hotelInfo"><?php echo htmlspecialchars_decode($areaInfo) ?></div>

htmlspecialchars_decode

【讨论】:

  • 不客气。如果您还想删除所有 HTML 标记,您可以在解码 HTML 特殊字符后运行strip_tags。对于所有这些基本功能,PHP 已经内置了有用的功能。
【解决方案2】:

我认为您必须使用 XML 的 XSL 转换。

详情请见http://php.net/manual/en/book.xsl.php

【讨论】:

  • 如何用火箭炮杀死苍蝇。
  • 我看了这个,什么都不懂。你觉得你能给我举个例子吗?
  • @WhitneySarahRogers 正如我对 Daniel 所说,XSL 转换是一个非常强大的复杂工具。无需学习和使用此类工具即可解决您的小格式问题。
  • @lorenzo-s:XSL 甚至不能在这里工作,因为有问题的字符串不是 XML。所以即使它很强大,它在这里也没有任何力量;)
猜你喜欢
  • 2018-02-24
  • 1970-01-01
  • 2015-07-11
  • 2011-04-25
  • 2012-02-17
  • 1970-01-01
  • 2021-04-19
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多