0

我试图将一个 XML 对象放入一个数组中,但我得到一个空数组,但我不知道为什么。

<?php

$string = '<?xml version="1.0" encoding="UTF-8"?>
            <confgs>
            # System Settings #
            ############################################################
            ## Login Account Settings

            ADMIN_ID="<confg rang="0" soort="veld" name="config1" />"
            ADMIN_ID="<confg rang="1" soort="veld" name="config2" />"
            ADMIN_PASS="PKXUT1xxRoutIT"
            USER_ID="<confg rang="2" soort="veld" name="config3" />"
            USER_PASS="<confg rang="3" soort="optie" opties="opt1~opt2~opt3" name="config4" />"
            ## Time Adjust Settings
            TIME_ZONE="60"
            DST_ENABLE="Y"
            MAC_ADRES="<confg rang="4" soort="veld" name="config5" />"
            DST_START_MONTH="3"
            DST_START_ORDINAL_DAY="<stconfg rang="1" soort="veld" name="stanconf1" />"
            DST_START_ORDINAL_DAY="<confg rang="8" soort="optie" opties="deze~die~endit~optie~extra" name="kijkhetwerkt" />"
            DST_START_ORDINAL_DAY="5"
            DST_START_ORDINAL_DAY="<stconfg rang="2" soort="veld" name="stanconf2" />"
            DST_START_ORDINAL_DAY="<confg rang="5" soort="veld" name="config6" />"
            DST_START_ORDINAL_DAY="<confg rang="6" soort="optie" opties="dit~dat~bibobla" name="slelect" />"
            IETS_CONF_ORDINAL_CFG="<confg rang="7" soort="veld" name="ditveld" />"
            IETS_CONF_ORDINAL_CFG="<confg rang="9" soort="veld" name="hallo" />"
            </confgs>
          ';

    error_reporting(E_ALL ^ E_NOTICE);
    $dom = new DOMDocument();
    $dom->preserveWhiteSpace = false;
    $dom->loadXML($string);
    $confg = $dom->getElementsByTagName('confg');

    $form = array();
    $a = 0;

    foreach($confg as $configuratie){
        $a++;
        $form[$a] = $dom->saveXML($configuratie);
    }

print_r($form);
    ?>

这就是我得到的:

数组 ( [1] => [2] => [3] => [4] => [5] => [6] => [7] => [8] => [9] => [10] =>)

有些东西告诉我,我的代码循环通过所有 10 个元素,所以它必须在那里我如何抓住它?

4

1 回答 1

1

那是因为<confg ... />它们现在是 HTML 元素,不能在浏览器中显示,因为它们只是 HTML 标记。

如果您查看源代码,您将看到它们。

于 2012-10-05T08:24:05.860 回答