一直都是弄数据库方面的东西,
今天弄一个东西,要读取本地打开的文件中的内容并格式化输出,
请大家给个思路,该怎么写?需要注意哪些问题?
文件中的内容格式如下:
#seq,extno,mp,time,msg
433706,1234,123456789,20070117152741,%B5%C4%B5%C4%B5%C4%B5%C4
就是将这样一个list输出到有固定格式的html中谢谢
今天弄一个东西,要读取本地打开的文件中的内容并格式化输出,
请大家给个思路,该怎么写?需要注意哪些问题?
文件中的内容格式如下:
#seq,extno,mp,time,msg
433706,1234,123456789,20070117152741,%B5%C4%B5%C4%B5%C4%B5%C4
就是将这样一个list输出到有固定格式的html中谢谢
<?php
$filename = dirname(__FILE__)."\\test.txt";
$fp = @fopen($filename,"r") or die("Can't Open File!");
$char=fread($fp,filesize($filename));$ary_char = explode("\n",$char);
$ary_recordname = array();
$ary_record = array();
foreach ($ary_char as $key=>$value){
if(substr($value, 0,1) == "#"){
$tempstr = substr($value, 1, strlen($value));
$temp = explode(",",$tempstr);
foreach ($temp as $key1=>$value1){
$ary_recordname[] = $value1;
}
}else{
if(count($ary_recordname) > 1){
$temp = explode(",",$value);
foreach ($temp as $key1=>$value1){
$record[$ary_recordname[$key1]] = $value1;
}
$ary_record[] = $record;
}else{
break;
}
}
}print_r($ary_record);
echo $ary_record[1]["seq"];fclose($fp);
?>