2014-01-29 4 views
0

PHP에서 xml 콘텐츠를 표시 한 후 html 태그를 제거하는 방법은 무엇입니까? 나는 또한 strip_tags을 시도했지만 HTML 태그를 제거하기 위해 노력하고 있지 않습니까? PHP 페이지PHP에서 xml 콘텐츠를 표시 한 후 html 태그를 제거하는 방법?

<div style="width:50%" align="center"> <?php echo strip_tags($a) ?></div> 

** aboutus.xml 파일 **

<?xml version="1.0" encoding="UTF-8"?> 
<item><pubDate>Sat, 05 Oct 2013 14:43:39 +0500</pubDate> 

<title><![CDATA[Who We Are]]></title> 

<url><![CDATA[about-us]]></url> 

<meta><![CDATA[]]></meta> 

<metad><![CDATA[]]></metad> 

<menu><![CDATA[About Us]]></menu> 

<menuOrder><![CDATA[0]]></menuOrder> 

<menuStatus><![CDATA[]]></menuStatus> 

<template><![CDATA[template.php]]></template> 

<parent><![CDATA[]]></parent> 

<content> 
<![CDATA[&lt;h1&gt;Who We Are&lt;/h1&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt; 
&lt;h2&gt;About Desk&lt;/h2&gt; 
&lt;p&gt;&amp;nbsp;&lt;/p&gt; 
&lt;p&gt;&lt;span style=\&quot;text-align: justify;\&quot;&gt; 
Lorem Ipsum is simply dummy text of the printing and typesetting industry. 
Lorem Ipsum has been the industry\&#039;s standard dummy text ever since 
the 1500s, when an unknown printer took a galley of type and scrambled 
it to make a type specimen book. It has survived not only five centuries, 
but also the leap into electronic typesetting, remaining essentially unchanged. 
It was popularised in the 1960s with the release of Letraset sheets containing 
Lorem Ipsum passages, and more recently with desktop publishing software 
PageMaker including versions of Lorem Ipsum.&lt;/span&gt;&lt;/p&gt; 
]]> 
</content> 

</item> 

표시 내용에

PHP 코드

<?php 

$doc = new DOMDocument(); 
$doc->load('aboutus.xml'); 

$items = $doc->getElementsByTagName("item"); 
foreach($items as $item) 
{ 

$contents = $item->getElementsByTagName("content"); 
$content = $contents->item(0)->nodeValue; 
$a= $content; 
} 
?> 

디스플레이 XML 내용 스크린 샷

enter image description here

솔루션

<?php echo strip_tags(html_entity_decode($a)) ?> 
+0

코드는 참조 작동합니다 : https://eval.in/96248은'  즉해야 할 수도 있습니다, 그래서', 인코딩 된 더블 추가 str_replace. – ThW

답변

1

당신이보고있는 HTML 실제로 HTML 없습니다. <> 문자는 엔터티 &lt;&gt;으로 변경됩니다. html_entity_decode()으로 다시 변경할 수 있습니다.

그런 다음 strip_tags()을 사용하여 HTML을 제거하거나 HTML로 작동하도록 유지할 수 있습니다.

따라서, 예를 들어, 당신은 <?php echo strip_tags(html_entity_decode($a)) ?>에 자신의 코드에 <?php echo strip_tags($a) ?>을 바꿀 수

+0

답변을 설명해 주시겠습니까? – voodoo417

+1

@ voodoo417 더 설명해야 할 부분이 무엇입니까? – DampeS8N

+0

nodeValue를 읽으면 디코딩 된 엔터티가 반환됩니다. 추가적인 디코딩 필요 없음. – ThW

관련 문제