2

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?

2
  • 1
    Why are you using DOM to output HTML in php? Why not just echo it out directly as in echo $i->nodeValue ? Commented Nov 4, 2009 at 10:39
  • I have to modify an existing app... I'll see what I can do about that echo. Commented Nov 4, 2009 at 10:45

3 Answers 3

3
 $a->appendChild($i->nodeValue);

instead of having:

$a->appendChild($dom->createCDATASection($i->nodeValue));
Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

0

I think you can use the html_entity_decode() function.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.