Convert XML to a PHP Array

Convert XML to a PHP array right in your browser. Paste or upload XML and get a clean PHP array with options to format, ignore attributes, and export easily.

Paste your input above or import a file below.
No file chosen
Supported file types: .xml, .html, .htm, .json, .txt, .log, .ini, .yaml, .yml, .csv, .tsv, .css
Total characters: 0
Options
Pretty format
Ignore attributes
Maximize output

How to Use:

  • Paste your XML input or click Choose File to upload supported file types like .xml, .html, or .txt.
  • The tool parses your XML and converts it into a valid PHP array structure.
  • Use Pretty format to format the output with indentation for readability.
  • Enable Ignore attributes to skip XML attributes and only include tags and text.
  • Toggle Maximize output to expand the output box.
  • Use Copy Output to copy the result to your clipboard or Export to File to download it.
  • Press Clear All to reset the tool and reload defaults.

What Convert XML to a PHP Array can do:

Convert XML to a PHP Array transforms any well-formed XML into valid PHP array syntax you can copy and paste into your PHP scripts. It’s designed for developers who want to move structured XML data into PHP code quickly. You can choose to keep XML attributes or drop them, and the result is displayed in clean array() syntax. It’s live, instant, and works completely offline in your browser.

Example:

Before:

<book>
<title>The Hobbit</title>
<author>Tolkien</author>
</book>

After:

array(
'book' => array(
'title' => 'The Hobbit',
'author' => 'Tolkien',
)
)

Common Use Cases:

Useful for converting XML config files, feeds, or content blocks into PHP structures. Perfect when building import scripts, debugging third-party XML, or repurposing API data as native PHP arrays.

Useful Tools & Suggestions:

If you’re pulling data into PHP, try Convert XML to JSON first it’s often easier to read and manipulate before going array-mode. You could also use Convert JSON to a List if you want to preview how the data will break down into items.