note 116028 added to domdocument.save
| From: | ludvig at ergopedia dot no | Date: | Fri, 31 Oct 2014 10:22:01 +0000 |
| Subject: | note 116028 added to domdocument.save | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-200756@lists.php.net to get a copy of this message | ||
When creating a DOMDocument from scratch and saving it, the encoding will be utf-8, although
it's declared as iso-8859-1.
When loading an XML-file declared and saved as iso-8859-1, php will keep the correct encoding when
it's saved after changes are made.
Php converts files declared as iso-8859-1 to utf-8 internally. To add text containing special
characters, the text must be encoded as utf-8. When the document is saved, special characters are
converted to iso-8859-1.
To save an xml created from scratch, use fopen/fwrite and utf8_decode:
$doc = new DOMDocument('1.0', 'iso-8859-1');
//Add som nodes and text with apropriate methods
$f = fopen('xmlfile.xml', 'w+');
fwrite($f, utf8_decode($doc->saveXML()));
fclose($f);
----
Server IP: 195.139.129.18
Probable Submitter: 81.166.237.3
----
Manual Page -- http://php.net/manual/en/domdocument.save.php
Edit -- https://master.php.net/note/edit/116028
Del: integrated -- https://master.php.net/note/delete/116028/integrated
Del: useless -- https://master.php.net/note/delete/116028/useless
Del: bad code -- https://master.php.net/note/delete/116028/bad+code
Del: spam -- https://master.php.net/note/delete/116028/spam
Del: non-english -- https://master.php.net/note/delete/116028/non-english
Del: in docs -- https://master.php.net/note/delete/116028/in+docs
Del: other reasons-- https://master.php.net/note/delete/116028
Reject -- https://master.php.net/note/reject/116028
Search -- https://master.php.net/manage/user-notes.php