DOMDocument->__construct()

(no version information, might be only in CVS)

DOMDocument->__construct() --  Creates a new DOMDocument object

说明

class DOMDocument {

__construct ( [string version [, string encoding]] )

}

Creates a new DOMDocument object.

参数

version

The version number of the document as part of the XML declaration.

encoding

The encoding of the document as part of the XML declaration.

范例

例子 1. Creating a new DOMDocument

<?php

$dom
= new DOMDocument('1.0', 'iso-8859-1');

echo
$dom->saveXML(); /* <?xml version="1.0" encoding="iso-8859-1"?> */

?>


add a note add a note User Contributed Notes
b dot schoppmeier at bas-consult dot de
12-Jul-2006 04:53
Handling of document encoding seems to be inconsistent:

I created a document, loaded a HTML file, tweaked it a bit and pushed it to the browser as in

   $doc = new DOMDocument();
   $doc->loadHTML($file);
   /*
   manipulate the document
   /*
   $outString = $doc->saveXML();

Text from the HTML file was ruined if it contained umlauts.

Creating the document with

   $doc = new DOMDocument("1.0","ISO-8889-1");

solved this problem.

But, when I set attributes to DOMElements where the attribute value contained umlauts those values still
appeared ruined.

Explicitly converting the attribute value to utf-8 as in

   $element->setAttribute($name, utf8_encode($value));

solved that problem too.