How to quickly parse XML in PHP ?

Introduction Parsing XML with PHP

It is often quite essential to be able to parse a XML. Fin below the snippet code in php that allows you to quickly parse a XML in php



<?php

try {

$xml = simplexml_load_string($order_payload_xml);
if ($xml === false) {
echo "Failed loading XML: ";
foreach (libxml_get_errors() as $error) {
echo "<br>", $error->message;
}
}
$windsurferOrderId = (string)$xml->order['id'];
} catch (\Exception $e) {
$windsurferOrderId = 'No Windsurfer order Id';
}




Comments

Popular posts from this blog

Best PHP comment DockBlock !

How to fix pgDump dbeaver ?