2016-11-17 44 views
0

我需要寫入目錄中的所有文件。每個文件的大小約爲7 MB。如何控制在目錄中讀取文件的過程?

當我打開文件,我必須解析,保存並打開下一個文件。

我知道堆棧內存會出現問題。我怎樣才能控制這個更優化?

+0

'問題與堆棧memory'什麼問題? –

回答

2

請務必關閉文件中的每個文件被讀取後:

$myfile = fopen("webdictionary.txt", "r") or die("Unable to open file!"); 
echo fread($myfile,filesize("webdictionary.txt")); 
fclose($myfile); 
// $myfile = // next file 
// fclose($myfile) 
.... 
+0

如果這是HTML文件解析,我應該如何打開這個,使用DOMDocument後? – MisterPi

+0

試試這個:$ doc = new DOMDocument(); $ doc-> loadHTML(file_get_contents('file.html')); – user2693928

+0

但是如何關閉'file_get_contents'打開的文件? – MisterPi