frankperez87 / xml2array
This will convert a Simple XML string to a associative array.
Installs: 1 152
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 2
Forks: 0
Open Issues: 1
Requires (Dev)
- phpspec/phpspec: 2.1.0
This package is auto-updated.
Last update: 2024-12-14 17:08:39 UTC
README
This package allows you to easily convert a xml string to a associative array.
Example Usage
<?php // Load in the composer autoloader file require 'vendor/autoload.php'; // Sample XML String $xml = '<?xml version="1.0" encoding="UTF-8"?> <urlset> <url> <loc>http://www.google.com</loc> <changefreq>monthly</changefreq> <priority>1</priority> </url> <url> <loc>http://www.yahoo.com</loc> <changefreq>monthly</changefreq> <priority>1</priority> </url> <url> <loc>http://www.bing.com</loc> <changefreq>monthly</changefreq> <priority>1</priority> </url> </urlset>'; // Pass in XML String $parser = new XML2Array\Parser($xml); // Convert XML to Associative Array $output = $parser->toArray(); // Print out results print '<pre>'; print_r($output); print '</pre>';
Example Output
Array ( [url] => Array ( [0] => Array ( [loc] => http://www.google.com [changefreq] => monthly [priority] => 1 ) [1] => Array ( [loc] => http://www.yahoo.com [changefreq] => monthly [priority] => 1 ) [2] => Array ( [loc] => http://www.bing.com [changefreq] => monthly [priority] => 1 ) ) )