(PHP 5, PHP 7, PHP 8)
DOMDocument::save — Sauvegarde l'arbre interne XML dans un fichier
Crée un document XML depuis la représentation DOM. Cette fonction est habituellement appelée après la construction d'un nouveau document DOM, comme dans l'exemple ci-dessous.
filename
Le chemin où sera sauvegardé le document XML.
options
Options additionnelles. Actuellement, seul LIBXML_NOEMPTYTAG est supporté.
Retourne le nombre d'octets écrit ou false
si une erreur survient.
Exemple #1 Sauvegarde d'un arbre DOM dans un fichier
<?php
$doc = new DOMDocument('1.0');
// nous voulons un bel affichage
$doc->formatOutput = true;
$root = $doc->createElement('book');
$root = $doc->appendChild($root);
$title = $doc->createElement('title');
$title = $root->appendChild($title);
$text = $doc->createTextNode('This is the title');
$text = $title->appendChild($text);
echo 'Écrit : ' . $doc->save("/tmp/test.xml") . ' bytes'; // Écrit : 72 bytes
?>