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
}

問題は、すでに配列内にある場合に書き込む必要があるifelseステートメントにあります。

4

1 に答える 1

2

$todaytodaydateする必要があります$todaydate

于 2012-11-01T16:57:59.430 に答える