3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php class generateXML { function __construct() { $this->xmlCreate(); } function __destruct() { } function xmlCreate() { $dataArray = Array ( "name" => "Sunil", "age" => 21, "city" => "Gzb", ); $doc = new DOMDocument('1.0'); $doc->formatOutput = true; $root = $doc->createElement('user'); $root = $doc->appendChild($root); foreach ($dataArray as $key => $value) { $title = $doc->createElement($key); $title = $root->appendChild($title); $text = $doc->createTextNode($value); $text = $title->appendChild($text); } echo $doc->saveXML() . "\n"; // echo "Document saved\n"; // echo "Saving only the title part:\n"; } } ?>
Output for 4.3.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0