用php打印xml [英] Print xml with php
问题描述
我有这个 php 代码
I have this php code
<?php
$status_code=1;
echo "<?xml version=\"1.0\"?>\n";
echo "<response>\n";
echo "\t<status>$status_code</status>\n";
echo "\t<time>" . time() . "</time>\n";
if ($status_code == 1) {
echo "\t<message>\n";
echo "\t\t<author>Vlad</author>\n";
echo "\t\t<text>Ova e poraka</text>\n";
echo "\t</message>\n";
}
echo "</response>";
?>
为什么我在浏览器中没有得到打印的 xml 代码?
Why I don't get the printed xml code in browser?
通过直接在 php 中打印 xml 代码来创建 ajax 请求还是我应该使用一些 xml php 函数来创建 xml 代码的好习惯?
Also is it good practice to create ajax requests by printing the xml code directly in php or should I use some xml php function to create xml code?
我想使用这个教程,但我得到的错误是上面打印的 xml 格式不正确
I wanted to create a chat system by using jquery, ajax, php and mysql using this tutorial, but I get error that the above printed xml is not well formed
推荐答案
正如其他人所说,你需要给浏览器一个标题,让它知道如何显示页面.
As the others have said, you need to give the browser a header to let it know how to display the page.
至于 xml 函数,请查看 PHP SimpleXMLElement
As for xml functions, have a look at the PHP SimpleXMLElement
这篇关于用php打印xml的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!