上面是读出的数据,问题有三:
第一、如何让日期时间正确显示;
第二、如何把第二第三列前面的"0^"去掉;
第三、如何在去掉小数前面的符号的之后给小数向后进位。比如把0.0630变成63
以上三问感谢回答,感激不尽!
以下是读取XML的代码:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>函谷关小时数据</title>
<style type="text/css">
body{margin: 0;}
.main{
width: 600px;
margin-top: 10px;
margin-left:auto;
margin-right:auto;
}
.table{width: 100%;background-color: transparent;border-collapse:collapse;border-spacing:0}
.table th,.table td{padding:8px;line-height:20px;text-align: center;}
.table-border{border-top:1px solid #ddd;}
.table-border th,.table-border td{border-bottom: 1px solid #ddd;}
.table-bg thead{background-color: #f5fafe;}
.tableselected{background-color: #f5fafe;}
.table-bordered{border:1px solid #ddd;border-collapse:separate;*border-collapse:collapse;border-left:0}
.table-bordered th,.table-bordered td{border-left:1px solid #ddd}
.table-border.table-bordered{border-bottom:0}
.table-hover tbody tr:hover td{background-color:#f5f5f5}
</style>
</head>
<body>
<div class="main" >
<table class="table table-border table-bordered table-bg table-hover">
<thead>
<tr>
<th width="200">日 期</th>
<th width="200">PM10</th>
<th width="200">PM2.5</th>
</tr>
</thead>
<tbody>
<?php
$dir='xml/'; //文件夹下的所有文件
function readxml($dir,&$arr){
if($handle=opendir($dir)){
while(false!==($file=readdir($handle))){
$sub_dir=$dir.DIRECTORY_SEPARATOR.$file;
if(is_dir($sub_dir)&&$file!='.'&&$file!='..'){
readxml($sub_dir,$arr);
}elseif(preg_match('/\.xml$/',$file)){
$arr[]=$sub_dir;
}
}
}
}
readxml($dir,$arr);
foreach($arr as $x){
$doc = new DOMDocument();
$doc->load ($x);
$UpLoadObjects = $doc->getElementsByTagName('UpLoadObject');
foreach($UpLoadObjects as $UpLoadObject){
$sub_dir;
$tms = $UpLoadObject->getElementsByTagName("tm");
$tm = $tms->item(0)->nodeValue;
$PM10s = $UpLoadObject->getElementsByTagName("PM10");
$PM10 = $PM10s->item(0)->nodeValue;
$PM25s = $UpLoadObject->getElementsByTagName("PM25");
$PM25 = $PM25s->item(0)->nodeValue;
}
?>
<tr>
<td><?php echo $tm; ?></td>
<td><?php echo $PM10; ?></td>
<td><?php echo $PM25; ?></td>
</tr>
<?php
}
?>
</tbody>
</table>
</div>
</body>
</html>