Really dirty xml output. Need to import into mysql but, any sugestions on how to clean the print view so I know what I'm working with?




<?php
$map_url = "http://ift.tt/1AP5BNq";


//Get and parse XML data. This code comes from and has explinations here.
//http://ift.tt/1uCp8sd

if (($response_xml_data = file_get_contents($map_url))===false){
echo "Error fetching XML\n";
} else {
libxml_use_internal_errors(true);
$data = simplexml_load_string($response_xml_data);
if (!$data) {
echo "Error loading XML\n";
foreach(libxml_get_errors() as $error) {
echo "\t", $error->message;
}
} else {
print_r($data);
}


This code reads the xml file then shows print_r. BUt this code I've found



function xml2array ( $xmlObject, $out = array () )
{
foreach ( (array) $xmlObject as $index => $node )
$out[$index] = ( is_object ( $node ) ) ? xml2array ( $node ) : $node;

return $out;
}


Is supposed to turn it into an array.


but I can't figure out how to merge the two. I then want to insert it into a mysql database but that is after I can figure out how to turn it into an array.


Thanks


Brandon


No comments:

Post a Comment