I read 11mb textfile with php:
$data_array = array();
$counter = 0;
while(!feof($fh)) {
$buffer = fgets($fh, 4096);
$data_array[$counter] = $buffer;
$counter++;
}
Then I want to use implode function to get all into one variable.
$data = implode("",$data_array);
But the script does nothing. If I try to store data into one variable during the loop, it takes ve开发者_C百科ry long time.
Is there some other way how to do this? I need to have data from 11mb textfile in one variable in php.First of all, you're trying to reinvent the wheel. There is already function in PHP for that:
$data = file_get_contents($filename)
Second, if you're not getting any results, check the memory and time limits you have set in php.ini
.
have you tried $data = file_get_contents('filename');
?
You should try to make the text file smaller parts if you can. Also there's execution limit in php.ini file 30 seconds should be default after which the script is terminated.
精彩评论