I'm trying to read a text file (134 KB, 3500 lines) into an array using this code:
$fp = fopen("myfile.txt", "r");
$temp = fread ($fp, filesize ("myfile.txt"));
$datalines = explode ("\n", $temp);
However the elements of the $datalines array are empty, i.e. they do not contain the lines of the file.
Before doing this I tried:
$datalines = file ("myfile.txt");
getting an array with 3500 empty elements. What can I do? Needless to say, I'm quite frustrated. In any major programming language you can declare an array of a predefined size, it exists and it is able to store what it has to store.
I might add that in a second step I want to sort the lines of this array using a sort function (will probably use a simple bubblesort). So I really need the array data structure otherwise the sorting gets quite difficult.
By the way, my provider has PHP 4.2.