需要安装两个组件XML/Serializer,XML/Util 代码如下:
$employees = array(
array(
'name' => 'Jimi',
'department' => 'Sales',
'email' =>
),
array(
'name' => 'Cindy',
'department' => 'Financial',
'email' =>
),
array(
'name' => 'Ruby',
'department' => 'Marketing',
'email' =>
)
);
require_once 'XML/Serializer.php';
// 初始化
$serializer = new XML_Serializer(array(
"indent" => "\t", // 缩进, 也可为空格
"linebreak" => "\n", // 换行符
"typeHints" => false, // 附带每个节点的 PHP 类型
"addDecl" => true, // 加入 XML 文档头
"encoding" => "UTF-8", // 文档编码
"rootName" => "employees", // 根节点名称
"defaultTagName" => "employee" // 默认节点名称
));
$serializer->serialize($employees);
header('Content-Type: application/xml');
echo $serializer->getSerializedData();
阅读(1480) | 评论(0) | 转发(0) |