see my Search in php from dat file, This is my code so far:
You would have to open the file using fopen or file_get_contents, then you would explode or split on newlines \n or \r\n (depending on OS and file).
Then, you could loop through them and explode that string again to see if the first element is what you are looking for. Like so:
$resLines = explode("\n", $FileContents);
foreach ($resLines as $line) {
$resLine = explode("|", $line);
if ($resLine[0] == $Search) {
echo "Found! $line";
}
}
Update regarding your edit
It would be something like this:
$resContents = file_get_contents("order.dat");
$resLines = explode("\n", $FileContents);
foreach ($resLines as $line) {
$resLine = explode("|", $line);
if ($resLine[0] == $Search) {
$aFound = $resLine; // setting our array with the found contents
}
}
echo "
Order number
Tranasaction id
Date
Total Price
" . $aFound[0] . "
" . $aFound[1] . "
" . $aFound[2] . "
" . $aFound[3] . "
";