2008年我们一起努力~Oh,YES!
读取修改XML文档
上一篇 /
下一篇 2008-04-14 10:03:18
<?xml version="1.0" encoding="UTF-8"?>
<pie>
<!--
<message bg_color="#CCBB00" text_color="#FFFFFF">
<![CDATA[You can broadcast any message to chart from data XML file]]>
</message>
-->
<slice title="服务器1" pull_out="true" descrīption="4026小时41分钟">14496075</slice>
<slice title="默认天数" descrīption="360小时19分钟">1297151</slice>
<slice title="Never" url="http://www.interactivemaps.org" descrīption="Click on the slice to find more information" alpha="50">0</slice>
</pie>
$doc = new DOMDocument();
$doc->load('ampie/ampie_data.xml');
//查找 pie 节点
$root = $doc->getElementsByTagName('pie');
//第一个 pie 节点
$root = $root->item(0);
//查找 pie 节点下的 slice 节点
$slice = $root->getElementsByTagName('slice');
//遍历所有 slice 节点
foreach ($slice as $rootdata)
{
foreach ($rootdata->attributes as $attrib)
{
$attribName = $attrib->nodeName; //nodeName为属性名称
$attribValue = $attrib->nodeValue; //nodeValue为属性内容
//查找属性名称为ip的节点内容
if ($attribName =='title')
{
if (iconv("UTF-8","gb2312",$attribValue)==$server_array[$i]["name"])
{
//修改文本
$tatoltime=floor($SUMTimeLengthALL/3600)."小时".date ("i分钟",$SUMTimeLengthALL);
$rootdata->setAttribute('descrīption',iconv("gb2312","UTF-8",$tatoltime));
$rootdata->nodeValue=$SUMTimeLengthALL;
}
if (iconv("UTF-8","gb2312",$attribValue)=="默认天数")
{
//另一个部分默认天数
$parttime1=floor($SUMTimeLength/3600)."小时".date ("i分钟",$SUMTimeLength);
$rootdata->setAttribute('descrīption',iconv("gb2312","UTF-8",$parttime1));
$rootdata->nodeValue=$SUMTimeLength;
}
$doc->save('ampie/ampie_data.xml');
}
}
}
相关阅读:
- smarty精髓之三 (亲情树, 2008-4-10)
- smarty精髓之五 (亲情树, 2008-4-10)
- smarty精髓之六 (亲情树, 2008-4-10)
- PHP上发现严重安全漏洞 (foxcamel, 2008-4-10)
- 超强分页类2.0发布,支持自定义风格,默认4种显示模式 (亲情树, 2008-4-11)
- ZendFramework 1.5 (liyong98847, 2008-4-11)
- PHP中常用的数组函数 (木林森, 2008-4-11)
- 预载入和JavaScript Image()对象 (liexusong, 2008-4-12)
- 什么是 Kohana? Kohana 与 CodeIgniter 的区别? (szlinz, 2008-4-12)
- 购物车类 (亲情树, 2008-4-12)
导入论坛
收藏
分享给好友
管理
举报
TAG:
php
xml