tags:

views:

206

answers:

3

Hi,

I have the following contents in my XML file:

<items>
<item id="1"><content><![CDATA[<p>string</p>]]></content></item>
</items>

I have HTML inside the content, so, I used CDATA. However, when I'm trying to display the content as HTML on the web page:

$item_content = $xpath2->query("/bulletin/item[@id='$item_id']/content");
foreach ($item_content as $i)
{
    $a = $dom->createElement('div');
    $a->appendChild($dom->createCDATASection($i->nodeValue));
    // $child = $dom->createElement('div',$i->nodeValue); <--this fails miserably
    $content_tag->appendChild($a);
}

It will get displayed as:

&lt ;p&gt ;string&lt ;/p&gt ;

How do I display it as HTML?

A: 

With html_ entity_decode(), it's possible to convert the html entities to normal characters.

Ikke
A: 

I think you can use the html_entity_decode() function.

Gator Bill
+1  A: 
 $a->appendChild($i->nodeValue);

instead of having:

$a->appendChild($dom->createCDATASection($i->nodeValue));
dusoft