PHP
downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

DOMDocument::createAttribute> <DOMDocument
Last updated: Fri, 20 Jun 2008

view this page in

DOMDocument::__construct

(PHP 5)

DOMDocument::__construct — Crée un nouvel objet DOMDocument

Description

DOMDocument::__construct ([ string $version [, string $encoding ]] )

Crée un nouvel objet DOMDocument.

Liste de paramètres

version

Le numéro de version du document en tant que partie de la déclaration XML.

encoding

L'encodage du document en tant que partie de la déclaration XML.

Exemples

Exemple #1 Création d'un nouveau DOMDocument

<?php

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

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

?>



DOMDocument::createAttribute> <DOMDocument
Last updated: Fri, 20 Jun 2008
 
add a note add a note User Contributed Notes
DOMDocument::__construct
christian dot reinecke at web dot de
15-Jul-2008 07:09
If you get the error message "domdocument::domdocument() expects parameter 2 to be long, string given"  for a code sample like this:

$dom = new DOMDocument('1.0', 'UTF-8');
$dom->xmlStandalone = false;
echo $dom->saveXML();

which is obviously correct if you compare the constructor signature:

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

make sure you're not overwritting this dom library by another (f.e. extension=php_domxml.dll in php.ini). XAMPP f.e. delivers its standard version with php_domxml.dll which ends up in this error message
dave at revlob dot com
14-Feb-2008 02:07
@Jarl

Not sure if this is what you meant when you said "The constructor example clearly shows that version and encoding only end up in the XML header", but you can also affect other parameters in the generated XML header, by accessing the DOMDocument's properties, for example:

<?php

$dom
= new DOMDocument('1.0', 'UTF-8');
$dom->xmlStandalone = false;
echo
$dom->saveXML();

// <?xml version="1.0" encoding="UTF-8" standalone="no"?>
bholbrook at servillian dot com
05-Dec-2007 02:25
Make sure that php_domxml.dll on windows is removed before using the domdocument class as they cannot coexist.
jarl kringelding skim punt com
24-Sep-2007 02:22
Be aware using the encoding parameter in the constructor.
It does not mean that all data is automatically encoded for you in the supplied encoding. You need to do that yourself once you choose an encoding other than the default UTF-8. See the note on DOM Functions on how to properly work with other encodings...

The constructor example clearly shows that version and encoding only end up in the XML header.

DOMDocument::createAttribute> <DOMDocument
Last updated: Fri, 20 Jun 2008
 
 
show source | credits | stats | sitemap | contact | advertising | mirror sites