dongshuo9350 2017-12-15 15:45
浏览 153
已采纳

php读写文件

function readWrite() {
    $fileReader = fopen('file.txt', 'r') or die("ERROR: File not found");
    $fileWriter = fopen('filewr.txt', 'w') or die ("ERROR: Write File not 
    found");
    $totalDaysArr= array();
    $monthNumArr= array();
    $monthArr= array();
    $row= file("file.txt");

    while($row = fgets($fileReader, 4096)) {
      list($monthNumArr[], $monthArr[], $totalDaysArr[]) = explode(",", $row);
    }

    for($x = 11; $x >= 0; $x--)
    {
      $table = explode(",", $monthNumArr[$x]);
      fwrite($fileWriter, $row[$x]);
    }
    fclose($fileWriter);
}

I'm a beginner at PHP, so this is what I have so far. My objective is to make a function that will read a file called file.txt and then write it in reverse using arrays. I'm not sure what I am doing wrong here.

These are the requirements:

This function should use PHP array to store records (each line is a "record").

This function should use a PHP Loop to walk through the months names array and generate HTML5/CSS to display the table.

Create a function that writes the text file filewr.txt (reverse order).

This function should use PHP for loop to walk through the array in reverse order and write each array entry (line/record) to the filewr.txt file.

and also the txt file looks like this:

1,January,31

2,February,28

3,March,31

4,April,30

5,May,31

6,June,30

7,July,31

8,August,31

9,September,30

10,October,31

11,November,30

12,December,31
  • 写回答

1条回答 默认 最新

      报告相同问题?

      相关推荐 更多相似问题

      悬赏问题

      • ¥15 使用vs2019开发的动态链路库在win7环境下使用有问题
      • ¥30 quartus prime画电路图,要发源文件和电路图每个模块批注,源程序和仿真结果
      • ¥15 MFC滚动条如何正确使用
      • ¥15 缓冲区算法求面积,基于文献
      • ¥50 电路PCB原理图设计AD19
      • ¥15 openstack 云平台搭建 创建实例错误
      • ¥15 联想笔记本网页加载突然出了问题不知道什么原因
      • ¥30 python猜单词小游戏改错 简单!!急!
      • ¥20 python-wxauto库问题
      • ¥15 espidf相关问题请教