2012-11-01 39 views
0

我想這個腳本只插入一個獨特的日期到一個文本文件,但它不能正常工作:將獨特的日期爲txt文件

$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

'$ todaytodaydate'應該是'$ todaydate' – Wilq

+0

感謝的人...愚蠢的錯誤:/ – durian

回答

2

$todaytodaydate應該$todaydate