note 48188 deleted from function.dom-domdocument-createelement by tularis
| From: | tularis@php.net | Date: | Wed, 15 Dec 2004 07:08:07 +0000 |
| Subject: | note 48188 deleted from function.dom-domdocument-createelement by tularis | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-81811@lists.php.net to get a copy of this message | ||
Note Submitter: Craig Manley
----
In reply to: paul squigly-symbol allofus dot org
If you want special entities like the '&' to be used in elements then don't pass
your string as a parameter to createElement(), but instead do it like this:
$tasty = 'Fish & chips!';
$doc = new domDocument();
$doc->encoding = 'UTF-8';
$doc->formatOutput = true;
$root = $doc->createElement('Food');
$doc->appendChild($root);
$data_element = $doc->createElement('Tasty');
$root->appendChild($data_element);
$text = $doc->createTextNode($tasty);
$data_element->appendChild($text);
$doc->save('php://output');
The code above will produce this:
<?xml version="1.0" encoding="UTF-8"?>
<Food>
<Tasty>Fish & chips!</Tasty>
</Food>
----
Reason: useless example