Both fopen and file_get_contents read in the whole file (the first in an array, the second in a string.) So when you explode using fread, you're only storing the first three exploded elements.
You will need to either step through the array or incorporate fgets into your function to read it line by line, or fseek to seek the line pointer you want. This code will likely be incorrect, typing on the fly, but something like
list($id, $data, $ip) = getRow(DATABASE,1234);
or
list($id, $data, $ip) = getRow(DATABASE);
function getRow($file,$myid=null) {
$id=$desc=$ip=null;
$fd = fopen($file, "r") or die("Can not open file: $file");
if ($fd) {
while (($buffer = fgets($fd, 4096)) !== false) {
list($id,$desc,$ip) = explode($buffer);
if ($myid and ($myid==$id)) {
fclose($fd);
return array($id,$desc,$ip);
}
}
fclose($handle);
}
return array($id,$desc,$ip);
}
The down side is this is not very efficient to use as a "get row" for printing out a whole file, it would read the whole file up to the matching $id for each row, thus reading it as many times as you have lines. (In fact, it would be kind of piggish . . .) I'd write a different function for that one that only reads the file once.