我正在尝试使用此脚本仅在文本文件中插入唯一的日期,但它无法正常工作:
$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语句,如果它已经在数组中,应该写入它。
答案 0 :(得分:2)
$todaytodaydate
应为$todaydate