How do I get the complete line from a position gotten by strpos()?
Here is my code:
//$route_route sample: NAXOP UZ45 VIKIK
$route_waypoint = explode(" ", $route_route);
$file = "components/airways.txt";
$contents = file_get_contents($file);
foreach ($route_waypoint as $waypoint) {
//$waypoint sample: NAXOP
$pos = strpos($contents, $waypoint);
if ($pos === false) {
continue;
} else {
$line = fgets($contents, $pos); // Here is my problem
//line sample: MES,W714,005,NAXOP,38.804139,30.546833,149,000, ,L
list($fix, $lat, $lon, $sample_data1, $sample_data2) = explode(',', $line);
echo "$fix, $lat, $lon";
}
}
The main objective is localize "NAXOP", read his complete line, and echo some data. Any kind of help is welcome!
DISCLAIMER: if
VIKIK
comes beforeNAXOP
in $contents.VIKIK
Will not be found, if there are multiple occurrences ofNAXOP || UZ45 || VIKIK
only the first of each occurrence will be found.Here is a better program.
Here is test.dat
Here is the output