私はPHPにかなり慣れていないので、これはすでにどこかで答えられている可能性があります。ただし、私の問題に対する同様の答えが見つからなかったため、次のようになります。
「frozen.txt」というテンプレートファイルがあります。このファイルには、凍結されたアイテム番号のリストが含まれています。その内容は次のようになります
23476
23829
26974
また、毎日の売上データを表す約 20 個のファイルがあります。「frozen-4-1.txt」、「frozen-4-2.txt」、「frozen-4-3.txt」などです。各 txt ファイルには、区切り記号で区切られた 3 つの列が含まれています。 ";" . 最初の列は "frozen.txt" とまったく同じです。2列目は「Each」単位の在庫数、3列目は「Box」単位の在庫数です。たとえば、「frozen-4-1.txt」は次のようになります。
23476;30;3
23829;100;10
26974;50;5
「frozen-4-2.txt」は次のようになります
23476; 20; 2
23829; 90; 9
26974; 40; 4
「frozen-4-3.txt」は次のようになります
23476; 10; 1
23829; 60; 6
26974; 20; 2
ここで、「outputeach.dat」と「outputbox.dat」という 2 つの新しいファイルを作成します。このファイルは「frozen.txt」を最初の列として使用し、日次データ txt ファイルの 2 列目と 3 列目をそれぞれ新しい列として使用します。 .(";" で区切られます) したがって、"outputeach.dat" は次のようになります。
23476;30;20;10
23829;100;90;60
26974:50;40;20
「outputbox.dat」は次のようになります
23476;3;2;1
23829;10;9;6
26974:5;4;2
これを達成しようとしている私のコードは次のとおりですが、プログラムの最後で立ち往生しています
<?php
include('path.php');
$space = "\r\n"; // For NewLine ...
$frzlist = array();
$readfrz = fopen("C:/purchase/dailydata/frozen.txt", "r");
while (!feof($readfrz)) {
$foo2 = fgets($readfrz);
$trufoo2 = trim( preg_replace( '/\s+/', ' ', $foo2 ) ); // get rid of new line in $foo2
$frzlist[] = $trufoo2; // read all the frozen item list into array $frzlist
}
fclose($readfrz);
if ($handle = opendir(BASE_PATH)){
while (false !== ($file = readdir($handle)))
{
if ($file == "." || $file == ".."){}else
{
if(!strstr($file,"txt"))
{
continue; //Skip as file is not txt format
}
$s = explode("-",$file);
$prefix = $s[0];
$prefix1 = $s[1];
$prefix2 = $s[2];
//echo $prefix . " "; // representing catogory
//echo $prefix1 . " "; // representing month
//echo $prefix2 . " "; // representing day
}
}
}
for($i=1 ; $i<32; $i++){ //loop through one month data
$days = $prefix1 . "-" . $i ;
$file1 = BASE_PATH . $prefix . "-" . $prefix1 . "-" . $i . ".txt" ;
//echo $file1 . "\n";
//echo $days . "\n";
if (file_exists($file1)) {
$fileopen1 = fopen($file1,"r");
while (!feof($fileopen1)) {
$foo = fgets($fileopen1);
$members1[] = $foo; // read all the contents into array $members1
}
$outputfrzpri = array();
$outputfrzsec = array();
if($prefix = "frozen"){
foreach ($members1 as $x1){
$pieces1 = explode(";", $x1);
CODE needs help here
CODE needs help here
}
}
}
}
?>
あなたのアドバイスは大歓迎です