Milos Cuculovic
Milos Cuculovic

Reputation: 20223

PHP DOMDocument does not keep numeric presentation of HTML special characters

I have a DOMDocument and would like to append some nodes.

In one of the nodes, I would like to put:

$copyrightStatementText = "© This is the CopyRight";

The problem is that the function:

$copyrightStatement = $dom_output->createElement('copyright-statement', $copyrightStatementText);

Is converting the © immediately to ©.

My goal is to keep the ©

Any idea how could I do that?

Upvotes: 0

Views: 112

Answers (1)

André Dion
André Dion

Reputation: 21708

From DOMDocument::createElement():

Note: The value will not be escaped. Use DOMDocument::createTextNode() to create a text node with escaping support.

So use DOMDocument::createTextNode() instead:

$copyrightString = "© This is the Copyright";
$copyrightNode = $dom_output->createTextNode($copyrightString);
$copyrightContainer = $dom_output->createElement('copyright-statement');

$copyrightContainer->appendChild($copyrightNode);

Upvotes: 1

Related Questions