3v4l.org

run code in 300+ PHP versions simultaneously
<?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 - 5.4.45, 5.5.24 - 5.5.35, 5.6.7 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.10, 7.2.0 - 7.2.33, 7.3.16 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
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.1.6, 5.2.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.3.11, 4.4.0 - 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.

preferences:
241.95 ms | 401 KiB | 311 Q