I’m working on a project where I needed to convert an XML doc into an associative array in PHP easily. I hadn’t done any work with XML in PHP yet, so I started digging around the usual places.

Soon, it looked like my best option would be to create a completely-custom XML parsing engine out of PHP’s built-in XML Parser. I started working on a set of code based off of the External Entity Example since that is the only example that actually incorporates the ability to retrieve data and not just attributes. My results were slow and very error prone. Why is this so tough? XML isn’t exactly new, and it is very widespread. Similarly, PHP is an extremely popular language. So, why is it so hard to combine the two and work with them easily? I shouldn’t have to create a custom syntax parser just to be able to read a standard format document into a PHP data structure.

Read More→