過程:array_unique不從文本文件導入的文件名字符串工作
- 用戶檢查複選框客戶
- 複選框值與存儲在從一個txt文件中的陣列相比佔共享文件
- 這些陣列是通過使用array_merge被合併成一個陣列相比客戶文件夾()
- 的重複使用array_unique消除()
- 新陣列寫入txt文件
問題:
如果我的文本文件已經包含了以下數據:
- 中號HTH A277幀(表示文本文件中的行號)關STD規格02-01-12.pdf
- M HTH A277框架在STD規格02-01-12.pdf
- M HTH選項可以價格列表02-02- 2012.xls
然後我嘗試共享更多文件,包括那些已經共享的文件。我的新的文本文件看起來像這樣:(表示文本文件中的行號)
- 中號HTH A277框關STD規格02-01-12.pdf
- (空白)
- 中號HTH A277幀STD規格02-01-12.pdf
- (空白)
- 中號HTH選項價目表02-02-2012.xls
- (空白)
- (空白)
- 中號HTH A277框關STD規格02-01-12.pdf
- 中號HTH A277幀STD規格02-01-12.pdf
- 中號HTH選項價目表02-02-2012.xls
- Valley Creek Estates - 2010.pdf
上面的值是我正在處理的確切值。我試圖儘可能徹底地解釋這個可能讓事情混亂的解釋。如果任何人可以提供任何建議,他們將不勝感激。提前致謝。這是我已經得到了到目前爲止的代碼:
的代碼:
$arr = $_POST['checked'];
$cust = $_POST['custname'];
if ($cust != ""){
$myFile = "CONTA.txt";
//If file exists get previous array from file
if (file_exists("customer/" . $cust . "/" . $myFile)) {
$fh = fopen("customer/" . $cust . "/" . $myFile, 'r') or die("");
while (!feof($fh)) {
$compare[] = fgets($fh);
}
fclose($fh);
//Combine checkbox array with previous array & eliminate duplicates
$combined = array_unique(array_merge($compare,$arr));
}
else
{
//Since no previous file or array existed. Just use current checkbox array.
$combined = $arr;
}
//Input array into file
$fh = fopen("customer/" . $cust . "/" . $myFile, 'w') or die("can't open file");
foreach ($combined as $value) {
fwrite($fh, $value . "\n");
}
echo "<span class='message'>Items shared successfully!</span>";
fclose($fh);
}
}
歡迎堆棧溢出!來自巴西? (''CONTA.txt';'這裏的單詞CONTAR與count相同,但是發音爲CONTA。) – 2012-04-08 03:42:06