<?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

Recommended Answers

All 5 Replies

Just have it

echo "\r\n";

Where it says // move to the next line

Member Avatar for rajarajan2017
<?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      }
} 

?>

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.

Sorry, I "misspoke." I edited my post, please check it again.

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.