Использование регулярных выражений будет быстрее
$data = file_get_contents("file.txt");
preg_match_all("/([0-9]{10}) ([0-9]{3}\.[0-9]{2})/",$data,$Matches);
//Use below if you want an associative array with the first 10 numbers
//being the keys and the second numbers being the values
$myData = array_combine($Matches[1],$Matches[2]);
([0-9]{10})
Матчи первые 10 цифр 0-9,
([0-9]{3}\.[0-9]{2})
сопоставляет следующий набор чисел, который имеет 3 число 0-9, то период, то 2 Чем больше номеров 0-9
$ матчи будут
Array
(
[0] => Array
(
[0] => 1303100643 115.83
[1] => 1303100644 115.94
[2] => 1303100645 115.80
[3] => 1303100646 115.99
[4] => 1303100647 115.74
[5] => 1303100648 115.11
)
[1] => Array
(
[0] => 1303100643
[1] => 1303100644
[2] => 1303100645
[3] => 1303100646
[4] => 1303100647
[5] => 1303100648
)
[2] => Array
(
[0] => 115.83
[1] => 115.94
[2] => 115.80
[3] => 115.99
[4] => 115.74
[5] => 115.11
)
)
код против кода:
JasonMcCreary
$time1=microtime();
$mydata = array();
$file_handle = fopen("data.txt","r");
while (!feof($file_handle)) {
set_time_limit(0);
$line_of_text = fgets($file_handle, 1024);
$reading=explode(" ", $line_of_text);
$mydata[] = $reading;
}
fclose($file_handle);
$time2 =microtime();
Чтение построчно и использование взрываются
1374728889 0.20137600 :: 1374728889 0.20508800
0.20508800
0.20137600
----------
0.00371200
Mine
$time1=microtime();
$data = file_get_contents("data.txt");
preg_match_all("/([0-9]{10}) ([0-9]{3}\.[0-9]{2})/",$data,$Matches);
$myData = array_combine($Matches[1],$Matches[2]);
$time2=microtime();
echo $time1." :: ".$time2;
Использование FGC и регулярные выражения
1374728889 0.20510100 :: 1374728889 0.20709000
0.20709000
0.20510100
----------
0.00198900
Вы спасатель: D – Waqas