3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $xml = <<<'XML' <?xml version="1.0"?> <books> <book> <isbn>123456789098</isbn> <title>Harry Potter</title> <author>J K. Rowling</author> <edition>2005</edition> </book> <book> <placeItHere></placeItHere> <isbn>1</isbn> <title>stuffs</title> <author>DA</author> <edition>2014</edition> </book> </books> XML; $book = [ 'isbn' => 123456789099, 'title' => 'Harry & Potter 3', 'author' => 'J K. Rowling', 'edition' => '2007' ]; $dom = new DOMDocument(); $dom->formatOutput = true; $dom->preserveWhiteSpace = false; $dom->loadXML($xml); $xpath = new DOMXPath($dom); $placeItHere = $xpath->query('/books/book/placeItHere')->item(0); $newBook = $placeItHere->appendChild($dom->createElement('book')); foreach ($book as $part => $value) { $element = $newBook->appendChild($dom->createElement($part, $value)); } echo $dom->saveXML();
Output for 5.4.0 - 7.2.0
Warning: DOMDocument::createElement(): unterminated entity reference Potter 3 in /in/cSeiv on line 38 <?xml version="1.0"?> <books> <book> <isbn>123456789098</isbn> <title>Harry Potter</title> <author>J K. Rowling</author> <edition>2005</edition> </book> <book> <placeItHere> <book> <isbn>123456789099</isbn> <title/> <author>J K. Rowling</author> <edition>2007</edition> </book> </placeItHere> <isbn>1</isbn> <title>stuffs</title> <author>DA</author> <edition>2014</edition> </book> </books>
Output for 5.3.0 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/cSeiv on line 22
Process exited with code 255.
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.2.17
Parse error: syntax error, unexpected T_SL in /in/cSeiv on line 3
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1, 5.0.0 - 5.0.5
Parse error: parse error, unexpected T_SL in /in/cSeiv on line 3
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/cSeiv on line 3
Process exited with code 255.