note 48188 added to function.dom-domdocument-createelement
| From: | CraigManley at osu1 dot php dot net | Date: | Tue, 14 Dec 2004 23:52:37 +0000 |
| Subject: | note 48188 added to function.dom-domdocument-createelement | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-81800@lists.php.net to get a copy of this message | ||
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>
----
Manual Page -- http://www.php.net/manual/en/function.dom-domdocument-createelement.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+48188
Delete -- http://master.php.net/manage/user-notes.php?action=delete+48188&report=yes
Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+48188&report=yes&reason=bad+code
Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+48188&report=yes&reason=spam
Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+48188&report=yes&reason=useless+example
Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+48188&report=yes&reason=contains+commercial+links
Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+48188&report=yes&reason=useless+note
Reject -- http://master.php.net/manage/user-notes.php?action=reject+48188&report=yes
Search -- http://master.php.net/manage/user-notes.php