简体   繁体   English

在PHP页面中回显或包含多个xml文件

[英]echo or include multiple xml files in php page

I wish to create a list of XML files in a php file. 我希望在php文件中创建XML文件列表。

I need all my xml files to be included in my php file. 我需要我所有的xml文件都包含在我的php文件中。 I have this working see below. 我有这个工作见下文。

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

when I try this it works well, now I try more than one. 当我尝试此方法时,效果很好,现在我尝试了不止一个。

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

it dose not read any of the files. 它不会读取任何文件。

I would try passing these files back in a JSON object. 我会尝试将这些文件传回JSON对象。

Create an array of files and then json_encode() that array. 创建一个文件数组,然后创建该数组的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);
?>

Now you will have a simple json object that you can process in the javascript and place 1 or many xml file(s) whereever you want to on the page using straight forward javascript 现在,您将拥有一个简单的json对象,您可以在javascript中进行处理,并使用简单的javascript将1个或多个xml文件放置在页面上的任何位置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM