わからない希望する期間に応じて、関数freadで読み込まれたバイトを調整する必要があります、あなたが他の前に、一つのファイルにファイルの終わりを打つ場合は、トラブルに遭遇するかもしれないが、彼らは同じ長さでない場合にのみ起こる:両方のファイルを開き、彼らとものを行う:
$file1 = fopen("/path/to/file1.txt","r"); //Open file with read only access
$file2 = fopen("/path/to/file2.txt","r");
$combined = fopen("/path/to/combined.txt","w"); //in case you want to write the combined lines to a new file
while(!feof($file1) && !feof($file2))
{
$line1 = trim(fgets($file1)); //Grab a line of the first file, note the trim will clip off the carriage return/new line at the end of the line, can remove it if you don't need it.
$line2 = trim(fgets($file2)); //Grab a line of the second file
$combline = $line1 . $line2;
fwrite($combined,$combline . "\r\n"); //Write to new combined file, and add a new carriage return/newline at the end of the combined line to replace the one trimmed off.
//You can do whatever with data from $line1, $line2, or the combined $combline after getting them.
}
注意$ line1または$ line2をに設定する制御文が必要な場合がありますまたは何か他の場合feof()
それぞれのファイル、一度両方のファイルの終わりにヒット、whileループが終了します。
「検索テーブル」とはどういう意味ですか?何を検索したいですか? –
2つのファイルのいくつかのデータが、行単位で結合され、次にtable1を検索し、結果をtable2に格納すると言う。 – limo
@limo:はい、* * *を検索しますか?ファイル構造とテーブルレイアウトの例を質問に追加してください。 –