从xml获取html标签并在php中回显?

时间:2012-03-18 17:30:22

标签: php html xml

我试图将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标签。

2 个答案:

答案 0 :(得分:2)

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

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

请参阅htmlspecialchars_decode

答案 1 :(得分:0)

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

有关详细信息,请参阅http://php.net/manual/en/book.xsl.php