在PHP页面中返回或包含多个XML文件


echo or include multiple xml files in php page

我希望在php文件中创建一个XML文件列表。

我需要我所有的xml文件包含在我的php文件。

<?php
header('Content-type: application/xml');
echo file_get_contents("exam1.xml");

当我试着这样做的时候,效果很好,现在我试了不止一个。

    <?php
header('Content-type: application/xml');
echo file_get_contents("exam1.xml");
echo file_get_contents("exam2.xml");

它不读取任何文件

我会尝试将这些文件以JSON对象的形式传递回去。

创建一个文件数组,然后json_encode()该数组。

<?php
    $f1 = file_get_contents("exam1.xml");
    $f2 = file_get_contents("exam2.xml");
    $response = array('files' => array($f1, $f2));
    echo json_encode($response);
?>

现在你将有一个简单的json对象,你可以在javascript中处理和放置一个或多个xml文件(s),无论你想在页面上使用直接的javascript