我想通過php處理一個CSV文件,並且讓它工作。但是有一個數組需要根據一組條件進行更改。if elseif indie while loop
$file_handle = fopen($path, "r");
while (!feof($file_handle)) {
$line_of_text = fgetcsv($file_handle, 100000);
if($currency == "US"){
$line_of_text[6] = str_replace ("if_you_find_this","change_to_this",$line_of_text[6]);
$line_of_text[6] = str_replace ("if_you_find_this","change_to_this",$line_of_text[6]);
} elseif($currency == "DE"){
$line_of_text[6] = str_replace ("if_you_find_this","change_to_this",$line_of_text[6]);
$line_of_text[6] = str_replace ("if_you_find_this","change_to_this",$line_of_text[6]);
}else {
echo "Something with currency handling went wrong. Please contact support.";
}
$data .= $line_of_text[0] . "," . $line_of_text[1] . "," . $line_of_text[2] . "," . $line_of_text[4] . "," . $line_of_text[6] . "," . $line_of_text[49] . "," . $line_of_text[51] . "\n";
}
fclose($file_handle);
$new_file_handle = fopen($path, "w");
fwrite($new_file_handle, $data);
它沒有拋出任何錯誤,但似乎整個條件塊被忽略。幫幫我?
忘記粘貼在已經在工作文件中的重要行 - > $ line_of_text = fgetcsv($ file_handle,100000); – jeffimperial 2012-03-02 05:56:58