使用php输出原始XML [英] Output raw XML using php

查看:66
本文介绍了使用php输出原始XML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想以类似于 http://www.google.com/的方式输出原始xml ig/api?weather = Mountain + View ,但使用PHP.

I want to output raw xml in a manner similar to http://www.google.com/ig/api?weather=Mountain+View but using PHP.

我的网络服务器上有一个非常简单的php脚本:

I have a very simple php script on my webserver:

<?php 

      $output = "<root><name>sample_name</name></root>";
      print ($output);
?> 

我在Chrome/firefox中只能看到"sample_name".我想看看:

All I can see in Chrome/firefox is "sample_name". I want to see:

<root>
     <name>sample_name</name>
</root>

我找不到简单的教程.

谢谢

推荐答案

默认情况下,PHP将Content-Type设置为text/html,因此浏览器将XML文档显示为HTML页面.

By default PHP sets the Content-Type to text/html, so the browsers are displaying your XML document as an HTML page.

要使浏览器将文档视为XML,您必须设置内容类型:

For the browser to treat the document as XML you have to set the content-type:

header('Content-Type: text/xml');

在打印脚本中的任何内容之前执行此操作.

Do this before printing anything in your script.

这篇关于使用php输出原始XML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆