The solution james438 proffered will work, but is far from optimal. It is very memory-intensive if you have a lot of data, since it loads it all into memory at once. I strongly agree with the opinions expressed thus far about how much easier and more efficient this would be with a proper database. However, here is a somewhat better way of doing it using a buffer:E.G.:Code:define('BUF_SIZ', 128);
define('TYPE_COLUMN', 0);
define('YEAR_COLUMN', 1);
define('ID_COLUMN', 2);
define('VALUE_COLUMN', 3);
function select_from_file($get, $where, $val, $multiple = false) {
$col %= 4;
$r = $multiple ? array() : '';
$f = open('yourfile.dat', 'r');
for($current_line = '', $next_line = '', $pos; !feof($file);) {
while(($pos = strpos($current_line, "\n")) === false)
$next_line .= fread($f, BUF_SIZ);
$next_line = str_replace("\r", '', $next_line);
list($current_line, $next_line) = explode("\n", $next_line, 2);
if($current_line) {
$current_line = explode(' ', $current_line);
if($current_line[$where] == $val)
if($multiple)
$r[] = $current_line[$get];
else {
$r = $current_line[$get];
break 2;
}
}
}
fclose($f);
return $r;
}
is -225816.67. You can also use it for other columns; select_from_file(TYPE_COLUMN, VALUE_COLUMN, '-226930.95') will return '#IB', and select_from_file(VALUE_COLUMN, TYPE_COLUMN, '#IB', true) will return an array of values from rows that begin with #IB (if you don't pass the $multiple argument, only the first one will be selected).Code:select_from_file(VALUE_COLUMN, ID_COLUMN, 2099) + select_from_file(VALUE_COLUMN, ID_COLUMN, 2641)
Untested.

