0

我正在尝试此脚本仅将唯一日期插入文本文件,但它无法正常工作:

$log_file_name = "logfile.txt";
$log_file_path = "log_files/$id/$log_file_name";

if(file_exists($log_file_path)){
  $not = "not";
  $todaydate = date('d,m,Y');
  $today = "$todaydate;";
  $strlength = strlen($today);
  $file_contents = file_get_contents($log_file_path);
  $file_contents_arry = explode(";",$file_contents);
  if(!in_array($todaytodaydate,$file_contents_arry)){
    $append = fopen($log_file_path, 'a');
    $write = fwrite($append,$today); //writes our string to our file.
    $close = fclose($append); //closes our file    
  }
  else {
    $append = fopen($log_file_path, 'a');
    $write = fwrite($append,$not); //writes our string to our file.
    $close = fclose($append); //closes our file    
  }
}
else{
  mkdir("log_files/$id", 0700);
  $todaydate = date('d,m,Y');
  $today = "$todaydate;";
  $strlength = strlen($today);
  $create = fopen($log_file_path, "w");
  $write = fwrite($create, $today, $strlength); //writes our string to our file.
  $close = fclose($create); //closes our file
}

问题在于 if else 语句如果它已经在数组中,则应该将其写入其中。

4

1 回答 1

2

$todaytodaydate应该$todaydate

于 2012-11-01T16:57:59.430 回答