3v4l.org

run code in 300+ PHP versions simultaneously
<?php $data = [ ['Code' => 'DES001', 'Commennte' => '', 'Quantity' => 1, 'Price' => '135.00', 'Unity' => 1] ]; // expected <value><![CDATA...</value> payload $payload = [ 'Pedido' => [ 'Nombre' => '', 'Producto' => [ 'Product' => [ [ 'ClaveProducto' => $data[0]['Code'], 'Cantidad' => $data[0]['Quantity'], 'Precio' => $data[0]['Price'], 'Unidad' => 'PIEZA', 'Comentario' => '', ] ] ], ] ]; // init domdocument $xml = new DOMDocument("1.0", "ISO-8859-15"); // optional $xml->preserveWhiteSpace = false; $xml->formatOutput = true; // create request wrapper $request = $xml->createElement("request"); // create method (CDATA), append it to the wrapper $method = $xml->createElement("method"); $method->appendChild($xml->createCDATASection('registra')); // create param wrapper $param = $xml->createElement("param"); // create name (CDATA), append it to the param $name = $xml->createElement("name"); $name->appendChild($xml->createCDATASection('pedido')); $param->appendChild($name); // create value (CDATA), append it to the param $value = $xml->createElement("value"); $value->appendChild($xml->createCDATASection(json_encode($payload))); $param->appendChild($value); // append method to request $request->appendChild($method); // append param to request $request->appendChild($param); // request root $xml->appendChild($request); // output echo $xml->saveXML($xml->documentElement);
Output for 7.3.0 - 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.4, 8.3.6
<request> <method><![CDATA[registra]]></method> <param> <name><![CDATA[pedido]]></name> <value><![CDATA[{"Pedido":{"Nombre":"","Producto":{"Product":[{"ClaveProducto":"DES001","Cantidad":1,"Precio":"135.00","Unidad":"PIEZA","Comentario":""}]}}}]]></value> </param> </request>
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 <request> <method><![CDATA[registra]]></method> <param> <name><![CDATA[pedido]]></name> <value><![CDATA[{"Pedido":{"Nombre":"","Producto":{"Product":[{"ClaveProducto":"DES001","Cantidad":1,"Precio":"135.00","Unidad":"PIEZA","Comentario":""}]}}}]]></value> </param> </request>

preferences:
145.2 ms | 402 KiB | 156 Q