在与第三方接口对接的时候,有时候对方返回的是xml格式数据,例如对方返回的xml是

<?xml version="1.0" encoding="utf-8"?>
<root>
	<name>vilay</name>
	<age>12</age>
</root>

我们如果直接用var_dump()输出,结果显示

string(82) "vilay12"

数据结构不明显,不利于我们处理数据和调试.

我们可以在输出之前,使用header()指定格式

<?php
$xml = '<?xml version="1.0" encoding="utf-8"?><root><name>vilay</name><age>12</age></root>';
header("Content-Type:text/xml; charset=UTF-8");
echo $xml;

结果显示:

This XML file does not appear to have any style information associated with it. The document tree is shown below.
<root>
<name>vilay</name>
<age>12</age>
</root>