PHP读写XML文件技巧
2012-12-04 20:42:27 来源:WEB开发网下面再给出一个完整的PHP中数据内容输出到XML文件的例子。该例子会对将一个PHP数组输出到XML文件中。
[php] <?php
//将数组输出到XML文件中
// by MoreWindows( http://blog.csdn.net/MoreWindows )
$article_array = array(
"第一篇" => array(
"title"=>"PHP访问MySql数据库 初级篇",
"link"=>"http://blog.csdn.net/morewindows/article/details/7102362"
),
"第二篇" => array(
"title"=>"PHP访问MySql数据库 中级篇 Smarty技术",
"link"=>"http://blog.csdn.net/morewindows/article/details/7094642"
),
"第三篇" => array(
"title"=>"PHP访问MySql数据库 高级篇 AJAX技术",
"link"=>"http://blog.csdn.net/morewindows/article/details/7086524"
),
);
$dom = new DOMDocument('1.0', 'UTF-8');
$dom->formatOutput = true;
$rootelement = $dom->createElement("MoreWindows");
foreach ($article_array as $key=>$value)
{
$article = $dom->createElement("article", $key);
$title = $dom->createElement("title", $value['title']);
$link = $dom->createElement("link", $value['link']);
$article->appendChild($title);
$article->appendChild($link);
$rootelement->appendChild($article);
}
$dom->appendChild($rootelement);
$filename = "D:\\test.xml";
echo 'XML文件大小' . $dom->save($filename) . '字节';
?>
<?php
//将数组输出到XML文件中
// by MoreWindows( http://blog.csdn.net/MoreWindows )
$article_array = array(
"第一篇" => array(
"title"=>"PHP访问MySql数据库 初级篇",
"link"=>"http://blog.csdn.net/morewindows/article/details/7102362"
),
"第二篇" => array(
"title"=>"PHP访问MySql数据库 中级篇 Smarty技术",
"link"=>"http://blog.csdn.net/morewindows/article/details/7094642"
),
"第三篇" => array(
"title"=>"PHP
更多精彩
赞助商链接