Php 非常脏的xml输出。需要导入mysql,但是,有没有关于如何清理打印视图的建议,以便我知道我';我和谁一起工作?

Php 非常脏的xml输出。需要导入mysql,但是,有没有关于如何清理打印视图的建议,以便我知道我';我和谁一起工作?,php,mysql,arrays,xml,Php,Mysql,Arrays,Xml,应该把它变成一个数组 但我不知道如何将两者合并。然后我想将它插入mysql数据库,但那是在我能够找到如何将它转换为数组之后 谢谢 布兰登 ////修改为 function xml2array ( $xmlObject, $out = array () ) { foreach ( (array) $xmlObject as $index => $node ) $out[$index] = ( is_object ( $node ) ) ? xml2array ( $n

应该把它变成一个数组

但我不知道如何将两者合并。然后我想将它插入mysql数据库,但那是在我能够找到如何将它转换为数组之后

谢谢

布兰登

////修改为

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

    return $out;
}

第一部分很简单。您当前有
print\r($data)的位置
,还添加类似于
$dataarray=xml2array($data)的内容。这将把xml数据保存在
$dataarray

然后,在数组中循环并运行insert querys:

<?php
$map_url = "http://archive.org/download/birdbookillustra00reedrich/birdbookillustra00reedrich_files.xml";


//Get and parse XML data. T
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);
      $dataarray = xml2array($data);
   }
}

for ($i = 0; $i++; $i < count($dataarray) {
   $item = $dataarray[$i];
   // Insert query here using $item.
}
?>
($i=0;$i{ $item=$dataarray[$i]; //使用$item在此处插入查询。 }

因为我不知道您的表结构,所以我无法帮助您解决这个问题。

(!)解析错误:语法错误,意外'{,应为'”,在C:\wamp\www\ebookstore\New folder\fopen2.php的第22行,您可以看到上面修改的代码。这是我如何将其组合在一起以获得错误的方式。@user3050153抱歉我的错误。我更新了我的答案;复制了编辑过的代码。浏览器可以通过可折叠的元素节点以非常好的方式显示XML文件。以下是可以重新格式化的在线服务XML。
<?php
$map_url = "http://archive.org/download/birdbookillustra00reedrich/birdbookillustra00reedrich_files.xml";


//Get and parse XML data. T
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);
      $dataarray = xml2array($data);
   }
}

for ($i = 0; $i++; $i < count($dataarray) {
   $item = $dataarray[$i];
   // Insert query here using $item.
}
?>
for ($i = 0; $i < count($dataarray); $i++) {
   $item = $dataarray[$i];
   // Insert query here using $item.
}