0
<?php

$file = 'GPSserial.txt' or die('could not open file!');
$handle = @fopen($file, "r") or die("could not open file!");

if ($handle) {
   while (!feof($handle)) {
      $buffer = fgets($handle, 4096);
      $GPSstr = $buffer;
      $GPSarray = explode(',', $GPSstr);   
      if ( $GPSarray[0] == '$GPGGA'){
        echo 'congrats';
      }
      else{
      // move to the next line
      }
}
?>

above is a code that opens a text file and scans it until eof is reached. basically the text file contains "sentences" that have begin with "headers" such as $GPGGA. Each sentence is written in a newline. can anyone help me such that once the header of the sentence is recognized as not being $GPGGA, the program would then move to the next line and check that "sentence's" header? thank you very much

3
Contributors
5
Replies
7
Views
7 Years
Discussion Span
Last Post by iwanttolearnc
0
<?php 
print "<br/>";
$file = '..\library\para.txt' or die('Could not read file!'); 
$data = file($file) or die('Could not read file!'); 
// loop through array and print each line 
foreach ($data as $line) { 
      $GPSarray = explode(',', $line);
      if ( $GPSarray[0] == '$GPGGA'){  
             echo 'congrats';  
       }      else
{      // move to the next line      }
} 

?>
0

sir to clarify things, should i append "\r\n" to the end of each line in the text file?
because if that be the case, i could not possibly do it. the text file is generated by several external sources and i cannot tinker with those.

0

thank you very much to those that replied! my problem was solved you guys are grea!

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.