Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

toniperic's avatar

XML Parsing

Is there a package I could use with Laravel 5 that lets me parse an XML easily? Other formats are also a plus but not necessary.

0 likes
16 replies
RushVan's avatar

I am fairly new to Laravel. Will this work for 5? If so, does it require pulling in the relevant code to a help macro or something?

RushVan's avatar

I guess more importantly, will this allow me to go JSON array -> XML.

1 like
Cicero's avatar

If you have a string containing XML and you want to convert it into an associative array:

// Load the XML
$xmlResponse = simplexml_load_string($response->getBody());

// JSON encode the XML, and then JSON decode to an array.
$responseArray = json_decode(json_encode($xmlResponse), true);
7 likes
christiangerdes's avatar

When working with large datasets, this approach might not be the best since you're loading the entire dataset into memory. Check XMLReader, perhaps?

Please or to participate in this conversation.