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);

preferences:
47.28 ms | 402 KiB | 5 Q