У меня есть переменная с XML, и я хочу, чтобы она была загружена с помощью кнопки загрузки, и я не могу найти способ сделать это. Ниже приведена последняя часть кода. Я хочу, чтобы эта переменная «newxml» загружалась как XML-файл. Как мне это сделать?Сделать переменную PHP с XML для загрузки
<?php
require_once('b.php');
$json = file_get_contents('sample.json');
$php_array = json_decode($json, true);
header("Content-type: text/xml");
$xml = Array2XML::createXML('root-element-here', $php_array);
$newxml=$xml->saveXML();
echo $newxml;
$file = 'XML.xml';
file_put_contents($file, $newxml);
?>
Я попытался сделать его загружаемым, как показано ниже, и это делает ошибку. может кто-то пожалуйста, сделать это правильно
<!DOCTYPE html>
<html>
<body>
<?php
require_once('b.php');
$json = file_get_contents('sample.json');
$php_array = json_decode($json, true);
header("Content-type: text/xml");
$xml = Array2XML::createXML('root-element-here', $php_array);
$newxml=$xml->saveXML();
$file = 'XML.xml';
file_put_contents($file, $newxml);
?>
<a href="XML.xml" download="sample.xml">Download XML</a>
</body>
</html>
Вот сообщение об ошибке
This XML file does not appear to have any style information associated with it. The document tree is shown below.
<html>
<body>
<a href="XML.xml" download="sample.xml">Download XML</a>
</body>
</html>
посмотреть эту тему: http://stackoverflow.com/questions/3552755/how-to-save-xml-using-php –
и после сохранения ваш файл создает ссылку с атрибутом 'download =" $ link ". –
Здесь моя проблема в том, что я не могу сделать это как файл HTML 5. ошибка выпрыгивает, когда я помещаю и другие теги, такие как и
. – user3725297