php - Finding and combining two strings from an array -


i have text file contains following lines, have read array called $pirep.

06:36  block block duratio n: 07:37  06:36  final fuel: 1044 lbls 

i have written code find "block block duration" , record time follows database. problem code cannot find string because text file broken down 1kb chunks, , happened fall right in middle of search string.

i understand how use str_replace(php_eol, '') join 2 strings, , great if data written @ same place every time, isn't.

is there way recognize time pattern precedes every line , combine lines until finds next occurrence of pattern, end result looks like:

06:36  block block duration: 07:37 06:36  final fuel: 1044 lbls 

this second question, , i'm hoping not on anyone's nerves this. thanks!

edit

here code using parse text file;

//read temp file array $pirep=file("temp.txt"); $num=count($pirep);  //assign known variables $pnum=explode(":",$pirep[2]); $dca=$pnum[1]; $fltnum=explode(":",$pirep[1]); $flt=$fltnum[1]; $date=$pirep[0]; //$dep=$pirep[5]; //$dest=$pirep[6];  //determine if mainenance division flight, set variable accordingly for($i=0;$i<$num;$i++) {     $line=$pirep[$i];     if(strpos($line,"maint")!==false) {         $maint="yes"; }  }  //cycle through pirep array , find departure , destination airports for($i=0;$i<$num;$i++) {     $line=$pirep[$i];     if(strpos($line,"departing airport")!==false) {         $dep=$pirep[$i]; } } for($i=0;$i<$num;$i++) {     $line=$pirep[$i];     if(strpos($line,"destination airport")!==false) {         $dest=$pirep[$i]; } }  //cycle through pirep , find block block duration for($i=0;$i<$num;$i++) {     $line=$pirep[$i];     if(strpos($line,"block block duration")!== false) {         $duration=ltrim(strstr($line,"duration"),"duration:");          $flttime=explode(":",$duration);         $minutes=($flttime[0]*60)+$flttime[1]; } }  //cycle through pirep , find comments if exist for($i=0;$i<$num;$i++) {     $line=$pirep[$i];     if(strpos($line,"comments")!== false) {         $raw_comments=ltrim(strstr($line,"comments "),"comments");         $comments=addslashes($raw_comments); } }  //connect dca , find pilot include('connect_db.php'); $stmt="select * newpilots dca=$dca limit 1"; $result=mysql_query($stmt); if(!$result) {echo"<br> query error<br>"; } if(mysql_num_rows($result)==0) {echo "<br>pilot $dca not found<br>"; } $count=mysql_num_rows($result);     $lastname=mysql_result($result,0,'lastname');     $firstname=mysql_result($result,0,'firstname');     $current_minutes=mysql_result($result,0,'minutes');     $email=mysql_result($result,0,'email');     $name=$firstname." ".$lastname;  //check empty maint , comment variables if(!isset($maint)) {$maint="no";} if(!isset($comments)) {$comments="none";} $timestamp=time(); $stmt="insert pireps values('','$dca','$name','$flt','$maint','$minutes','$comments','$timestamp')"; $result=mysql_query($stmt); if(!$result) {echo "query error";}  $updated_minutes = $current_minutes + $minutes; $stmt="update newpilots set minutes='$updated_minutes', lastfile='$timestamp', flag='yes' dca=$dca"; $result=mysql_query($stmt); if(!$result) {echo "query error updating roster"; }                      $to  = 'email@hidden.com, ';                     $headers = 'cc: '.$email."\r\n";                     $subject = "dc-3 airways fsacars pirep verification";                     if($maint=="yes") { $headers = 'cc: also.hidden.com' . "\r\n"; }                     $headers .= 'from: admin@dcascreenshots.net'."\r\n";                     $headers .= 'reply-to: admin@dcascreenshots.net'."\r\n";                     $body = "this automatic email generated dc-3 airways fsacars system. following information has been posted;      date submitted: $date     pilot $dca     flight number: $flt     $dep     $dest     duration: $duration     pilot's comments:     $comments  please log in aps system verify hours. if there discrepancy, please contact staff member.";                  if (!mail($to, $subject, $body, $headers)) {                     echo "email not sent.<br>"; } 

and here sample text file;

[2015/05/30 22:58:00] flight iata:pajn-padu pilot number:0309 company icao:dca aircraft type:dc3 departing airport: pajn destination airport: padu online: no route:rukie v317 csper t278 hapit v440 centa t269 yak v440 mdo t237 hom v321 akn t271 binal t227 mordi g8 zebuv flight level:10000 22:58  0 fuel weight: 21531 lbs, fuel weight: 4664 lbs 22:59  parking brakes off 22:59  take-off 22:59  take off weight: 26187 lbs 22:59  wind: 261º @ 010 knots heading: 281º 22:59  pos n58º 21´ 17´´ w134º 34´ 32´´  22:59  gear up: 119 knots 23:10  toc 23:10  fuel weight: 4545 lb 23:14  wind:313º@001 knots heading: 272º ground speed: 166 knots altitude 9996 ft 23:29  wind:322º@004 knots heading: 271º ground speed: 165 knots altitude 10059 ft 23:44  wind:313º@007 knots heading: 320º ground speed: 160 knots altitude 10042 ft 23:59  wind:297º@007 knots heading: 318º ground speed: 160 knots alt itude 10049 ft 00:14  wind:273º@008 knots heading: 317º ground speed: 161 knots altitude 10052 ft 00:28  simulation rate 2x 00:29  wind:279º@009 knots heading: 270º ground speed: 158 knots altitude 10055 ft 00:44  wind:289º@012 knots heading: 270º ground speed: 156 knots altitude 10072 ft 00:59  wind:292º@012 knots heading: 269º ground speed: 157 knots altitude 10072 ft 01:14  wind:288º@011 knots heading: 268º ground speed: 158 knots altitude 10075 ft 01:29  wind:273º@009 knots heading: 266º ground speed: 159 knots altitude 10078 ft 01:44  wind:261º@007 knots heading: 296º ground speed: 163 knots altitude 10062 ft 01:59  wind:260º@005 knots heading: 295º ground speed: 164 knots altitude 10032 ft 02:14  wind:238º@003 knots heading: 294º ground speed: 167 knots altitude 10026 ft 02:29  wind:345º@004 knots heading: 295º ground speed: 166 knots altitude 10082 ft 02:44  wind:356º@0 04 knots heading: 238º ground speed: 171 knots altitude 10009 ft 02:59  wind:040º@003 knots heading: 236º ground speed: 173 knots altitude 10022 ft 03:14  wind:070º@004 knots heading: 236º ground speed: 173 knots altitude 10052 ft 03:29  wind:111º@008 knots heading: 233º ground speed: 174 knots altitude 10045 ft 03:44  wind:137º@015 knots heading: 221º ground speed: 170 knots altitude 10036 ft 03:59  wind:174º@015 knots heading: 221º ground speed: 163 knots altitude 10068 ft 04:14  wind:182º@016 knots heading: 220º ground speed: 158 knots altitude 9940 ft 04:29  wind:172º@022 knots heading: 218º ground speed: 156 knots altitude 9885 ft 04:44  wind:164º@030 knots heading: 214º ground speed: 153 knots altitude 9921 ft 04:59  wind:168º@031 knots heading: 214º ground speed: 151 knots altitude 9937 ft 05:14  wind:164º@026 knots heading: 214º ground speed: 155 knots altitude 10029 f t 05:29  wind:158º@026 knots heading: 213º ground speed: 158 knots altitude 10000 ft 05:44  wind:162º@021 knots heading: 245º ground speed: 171 knots altitude 10006 ft 05:56  simulation rate 1x 05:59  wind:160º@023 knots heading: 243º ground speed: 170 knots altitude 10022 ft 06:14  wind:167º@016 knots heading: 217º ground speed: 160 knots altitude 10013 ft 06:15  tod 06:15  fuel weight: 1145 lb 06:26  gear down: 143 knots 06:26  flaps:1 @ 142 knots 06:27  flaps:2 @ 142 knots 06:29  wind:120º@006 knots heading: 191º ground speed: 108 knots altitude 2470 ft 06:31  flaps:4 @ 105 knots 06:34  touchdown:rate -124 ft/min speed: 58 knots 06:35  flaps:0 @ 39 knots 06:35  land 06:35  wind:335º@010 knots 06:35  heading: 139º 06:35  flight duration: 07:36  06:35  landing weight: 22577 lbs 06:35  pos n53º 53´ 54´´ w166º 32´ 38´´  06:36  parking brakes on 06:36  block block duratio n: 07:37  06:36  final fuel: 1044 lbls 06:36  spent fuel: 3619 lbls 06:36  flight length: 1221 nm 06:36  tod land length: 43 nm 

got it! works;

if($i>=15) { if(substr($line,2,1)!=":") {     $first_line=str_replace(php_eol,"",$pirep[$i-1]);     $line=$first_line.$pirep[$i];     echo $line."<br>";     } } 

Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - Bypass Geo Redirect for specific directories -

php - .htaccess mod_rewrite for dynamic url which has domain names -