3v4l.org

run code in 300+ PHP versions simultaneously
<?php set_time_limit(0); ini_set('display_errors', 1); ini_set('memory_limit', '1000M'); //read from csv $lines = file('E:\datalinks+.csv'); $dates=array(); foreach ($lines as $line_num => $line) { // echo "Line #<b>{$line_num}</b> : " . htmlspecialchars($line) . "<br />\n"; //$data =explode(",",strip_tags($line)); //$dates[]=date('Ymd',strtotime($data[0])); $dates[]="http://aviation-safety.net".$line; } print_r($dates); exit; //$data=array(); $replace=array('\n',','); $header=array('Status','Date','Time','Type','Operator','Leased from','Registration','msn','First Filght','Total airframe hrs','Engines','Crew','Passengers','Total','Ground casualties','Collision casualties','Cycles','Damage','Fate','Location','Phase','Nature','Depart Airport','Destination Airport','Flightnumber'); $str=implode(',',$header)." \n"; $i=1; //$data=array(array('status','date','time','type','registration','msn','FirstFlight','crew','passengers','total','Groundcasualties','Collisioncasualties','Flightnumber','Engines','Cycles','Totalairframehrs','Leased from','Operator','damage','fate','Location','Phase','Depart Airport','Destination','Departure')); foreach($dates as $id => $dval){ if($id<3000) continue; //else break; //print_r($dates); //exit; //echo "http://aviation-safety.net/database/record.php?id=".$dval."-0 <br>" ; //$data = file_get_contents("http://aviation-safety.net/database/record.php?id=".$dval."-0"); $content = file_get_contents($dval); //echo $data; //exit; //preg_match_all("/(<([table]+)[^>]*>)(.*)?<\/table>/", $data, $match); //print_r($match); //exit; $data[$i]['status'][$i]=0; $data[$i]['date'][$i]=0; $data[$i]['time'][$i]=0; $data[$i]['type'][$i]=0; $data[$i]['registration'][$i]=0; $data[$i]['msn'][$i]=0; $data[$i]['FirstFlight'][$i]=0; $data[$i]['crew'][$i]=0; $data[$i]['passengers'][$i]=0; $data[$i]['total'][$i]=0; $data[$i]['Groundcasualties'][$i]=0; $data[$i]['Collisioncasualties'][$i]=0; $data[$i]['Flightnumber'][$i]=0; $data[$i]['Engines'][$i]=0; $data[$i]['Cycles'][$i]=0; $data[$i]['Totalairframehrs'][$i]=0; $data[$i]['Leased from'][$i]=0; $data[$i]['Operator'][$i]=0; $data[$i]['damage'][$i]=0; $data[$i]['fate'][$i]=0; $data[$i]['Location'][$i]=0; $data[$i]['Phase'][$i]=0; $data[$i]['Destination'][$i]=0; $data[$i]['Departure'][$i]=0; //*************** //echo $data; $val = preg_split('<table>',$content); $val2 = preg_split('</table>',$val[1]); //echo strip_tags($val2[0]); $val3 = explode('</tr>',$val2[0]); // print_r($val3); //exit; $str.=" ,"; foreach($val3 as $in => $val4){ //if($in<3) continue; //else break; //draw Date $pos = strpos($val4, "Status"); if ($pos !== false) { $temp = explode(":",$val4); $test =str_replace($replace," ", trim(strip_tags($temp[1]))); //$str.=" '".strip_tags(stripslashes(trim($temp[1])))."',"; //$str.=" ".strip_tags(stripslashes(trim($test))).","; $data[$i]['status'][$i]=strip_tags(stripslashes(trim($test))); } //draw Date $pos = strpos($val4, "Date"); if ($pos !== false) { $temp = explode(":",$val4); $test =str_replace($replace," ", trim(strip_tags($temp[1]))); //$str.=" '".strip_tags(stripslashes(trim($temp[1])))."',"; //$str.=" ".strip_tags(stripslashes(trim($test))).","; $data[$i]['date'][$i]=strip_tags(stripslashes(trim($test))); } $pos = strpos($val4, "Time"); if ($pos !== false ) { //echo "Time found"; //exit; $time = explode(":",strip_tags($val4)); $str.=" ".$time[1].":".$time[2].","; $flag=1; $data[$i]['time'][$i]=strip_tags(stripslashes(trim(" ".$time[1].":".$time[2].""))); }else{ $pos = strpos($val4, "Type"); if ($pos !== false && $in==2) { $str.="00:00,"; $data[$i]['time'][$i]=strip_tags(stripslashes(trim("00:00"))); } } //draw Typpe //Type $pos = strpos($val4, "Type"); if ($pos !== false) { $temp = explode(":",$val4); $test =str_replace($replace," ", trim(strip_tags($temp[1]))); //$str.=" '".strip_tags(stripslashes(trim($temp[1])))."',"; //$str.=" ".strip_tags(stripslashes(trim($test))).","; $data[$i]['type'][$i]=strip_tags(stripslashes(trim($test))); } //draw //Registration $pos = strpos($val4, "Registration"); if ($pos !== false) { $temp = explode(":",$val4); $test =str_replace($replace," ", trim(strip_tags($temp[1]))); //$str.=" '".strip_tags(stripslashes(trim($temp[1])))."',"; //$str.=" ".strip_tags(stripslashes(trim($test))).","; $data[$i]['registration'][$i]=strip_tags(stripslashes(trim($test))); } //draw //msn $pos = strpos($val4, "msn"); if ($pos !== false) { $temp = explode(":",$val4); $test =str_replace($replace," ", trim(strip_tags($temp[1]))); //$str.=" '".strip_tags(stripslashes(trim($temp[1])))."',"; //$str.=" ".strip_tags(stripslashes(trim($test))).","; $data[$i]['msn'][$i]=strip_tags(stripslashes(trim($test))); } //draw //First Filght $pos = strpos($val4, "First flight"); if ($pos !== false) { $temp = explode(":",$val4); $test =str_replace($replace," ", trim(strip_tags($temp[1]))); //$str.=" '".strip_tags(stripslashes(trim($temp[1])))."',"; //$str.=" ".strip_tags(stripslashes(trim($test))).","; $data[$i]['FirstFlight'][$i]=strip_tags(stripslashes(trim($test))); } //echo strip_tags($val4)." -- ".$in."<br>"; $flag=0; $pos = strpos($val4, "Crew"); if ($pos !== false) { $temp = explode("/",strip_tags($val4)); $fat = explode(":",strip_tags($temp[0])); $occ = explode(":",strip_tags($temp[1])); //print_r($occ); //print_r($fat); $str.=" '".$fat[2]."' / '".$occ[1]."',"; $flag=1; $data[$i]['crew'][$i]=trim(" '".$fat[2]."' / '".$occ[1]."'"); } $pos = strpos($val4, "Passengers"); if ($pos !== false) { $temp = explode("/",strip_tags($val4)); $fat = explode(":",strip_tags($temp[0])); $occ = explode(":",strip_tags($temp[1])); //print_r($occ); //print_r($fat); $str.=" '".$fat[2]."' / '".$occ[1]."',"; $flag=1; $data[$i]['passengers'][$i]=trim(" '".$fat[2]."' / '".$occ[1]."'"); } $pos = strpos($val4, "Total:"); if ($pos !== false) { $temp = explode("/",strip_tags($val4)); $fat = explode(":",strip_tags($temp[0])); $occ = explode(":",strip_tags($temp[1])); //print_r($occ); //print_r($fat); $str.=" ".$fat[2]." / ".$occ[1].","; $flag=1; $data[$i]['total'][$i]=trim(" ".$fat[2]." / ".$occ[1].""); } $pos = strpos($val4, "Ground casualties"); if ($pos !== false) { $temp = explode(":",strip_tags($val4)); $test =str_replace($replace," ", trim(strip_tags($temp[1]))); //$str.=" ".strip_tags($temp[1]).","; $data[$i]['Groundcasualties'][$i]=trim(strip_tags($test)); $flag=1; } $pos = strpos($val4, "Collision casualties"); if ($pos !== false) { $temp = explode(":",strip_tags($val4)); $test =str_replace($replace," ", trim(strip_tags($temp[1]))); //$str.=" ".strip_tags($temp[1]).","; $data[$i]['Collisioncasualties'][$i]=trim(strip_tags($test)); $flag=1; } //Flightnumber $pos = strpos($val4, "Flightnumber"); if ($pos !== false) { $temp = explode(":",$val4); $test =str_replace($replace," ", trim(strip_tags($temp[1]))); //$str.=" '".strip_tags(stripslashes(trim($temp[1])))."',"; //$str.=" ".strip_tags(stripslashes(trim($test))).","; $data[$i]['Flightnumber'][$i]=trim(strip_tags($test)); } //Flightnumber $pos = strpos($val4, "Engines"); if ($pos !== false) { $temp = explode(":",$val4); $test =str_replace($replace," ", trim(strip_tags($temp[1]))); //$str.=" '".strip_tags(stripslashes(trim($temp[1])))."',"; //$str.=" ".strip_tags(stripslashes(trim($test))).","; $data[$i]['Engines'][$i]=trim(strip_tags($test)); } //Cycles $pos = strpos($val4, "Cycles"); if ($pos !== false) { $temp = explode(":",$val4); $test =str_replace($replace," ", trim(strip_tags($temp[1]))); //$str.=" '".strip_tags(stripslashes(trim($temp[1])))."',"; $str.=" ".strip_tags(stripslashes(trim($test))).","; $data[$i]['Cycles'][$i]=trim(strip_tags($test)); } //Total airframe hrs $pos = strpos($val4, "Total airframe hrs"); if ($pos !== false) { $temp = explode(":",$val4); $test =str_replace($replace," ", trim(strip_tags($temp[1]))); //$str.=" '".strip_tags(stripslashes(trim($temp[1])))."',"; //$str.=" ".strip_tags(stripslashes(trim($test))).","; $data[$i]['Totalairframehrs'][$i]=trim(strip_tags($test)); } //draw Leased from $pos = strpos($val4, "Leased from"); if ($pos !== false) { $temp = explode(":",$val4); $test =str_replace($replace," ", trim(strip_tags($temp[1]))); //$str.=" '".strip_tags(stripslashes(trim($temp[1])))."',"; //$str.=" ".strip_tags(stripslashes(trim($test))).","; $data[$i]['Leased from'][$i]=trim(strip_tags($test)); } //draw //Operator $pos = strpos($val4, "Operator"); if ($pos !== false) { $temp = explode(":",$val4); $test =str_replace($replace," ", trim(strip_tags($temp[1]))); //$str.=" '".strip_tags(stripslashes(trim($temp[1])))."',"; //$str.=" ".strip_tags(stripslashes(trim($test))).","; $data[$i]['Operator'][$i]=trim(strip_tags($test)); } //draw //Operator $pos = strpos($val4, "damage"); if ($pos !== false) { $temp = explode(":",$val4); $test =str_replace($replace," ", trim(strip_tags($temp[1]))); //$str.=" '".strip_tags(stripslashes(trim($temp[1])))."',"; //$str.=" ".strip_tags(stripslashes(trim($test))).","; $data[$i]['damage'][$i]=trim(strip_tags($test)); } //draw //Operator $pos = strpos($val4, "fate"); if ($pos !== false) { $temp = explode(":",$val4); $test =str_replace($replace," ", trim(strip_tags($temp[1]))); //$str.=" '".strip_tags(stripslashes(trim($temp[1])))."',"; //$str.=" ".strip_tags(stripslashes(trim($test))).","; $data[$i]['fate'][$i]=trim(strip_tags($test)); } //draw //Operator $pos = strpos($val4, "Location"); if ($pos !== false) { $temp = explode(":",$val4); $test =str_replace($replace," ", trim(strip_tags($temp[1]))); //$str.=" '".strip_tags(stripslashes(trim($temp[1])))."',"; //$str.=" ".strip_tags(stripslashes(trim($test))).","; $data[$i]['Location'][$i]=trim(strip_tags($test)); } $pos = strpos($val4, "Phase"); if ($pos !== false) { $temp = explode(":",$val4); $test =str_replace($replace," ", trim(strip_tags($temp[1]))); //$str.=" '".strip_tags(stripslashes(trim($temp[1])))."',"; $str.=" ".strip_tags(stripslashes(trim($test))).","; $data[$i]['Phase'][$i]=trim(strip_tags($test)); } //Depart Airport','Destination $pos = strpos($val4, "Destination"); if ($pos !== false) { $temp = explode(":",$val4); $test =str_replace($replace," ", trim(strip_tags($temp[1]))); //$str.=" '".strip_tags(stripslashes(trim($temp[1])))."',"; $str.=" ".strip_tags(stripslashes(trim($test))).","; $data[$i]['Destination'][$i]=trim(strip_tags($test)); } $pos = strpos($val4, "Departure"); if ($pos !== false) { $temp = explode(":",$val4); $test =str_replace($replace," ", trim(strip_tags($temp[1]))); //$str.=" '".strip_tags(stripslashes(trim($temp[1])))."',"; $str.=" ".strip_tags(stripslashes(trim($test))).","; $data[$i]['Departure'][$i]=trim(strip_tags($test)); } /* if($in !=7 && $in !=8 && $in !=9){ $temp = explode(":",$val4); $str.=" ".strip_tags($temp[1])." ,"; }else{ $temp = explode("/",strip_tags($val4)); $fat = explode(":",strip_tags($temp[0])); $occ = explode(":",strip_tags($temp[1])); print_r($occ); print_r($fat); $str.="".$fat[2]."/".$occ[1].","; } */ } //echo $str; //exit; //echo $str; // $val3; //exit; /* preg_match_all("/(<([\w]+)[^>]*>)(.*?)(<\/\\2>)/", $data, $matches, PREG_SET_ORDER); //preg_match_all("/<table>[\s\w\/<>=\\\"]*<\/table>/",$data,$matches); //print_r($val3); //print_r($matches); $i=23; while($i!=41){ $text = $matches[$i][0]; //echo $text."<br>"; if($i!=35 && $i != 36){ $vals = explode(":",strip_tags($text)); $str.=' '.$vals[1].' ,'; $i++; }elseif($i==36){ $str.=' '.$matches[$i][3].' ,'; $i++; }else{ $i++; } // echo $matches[$i][3]."<br>"; } */ //echo $str; //exit; //$str = substr($str,0,-5); //echo $str; $i++; //$str.=" \n"; if($id ==12000) break; }//end for loop //print_r($data); //exit; $str=''; $file='E:\sampleNew3k_12000.csv'; $f = fopen($file,'w+'); foreach($data as $id => $val){ //print_r($val); exit; foreach($val as $in => $v) $str.=''.$v[$id].","; $str = substr($str,0,-1)."\n"; //$str=implode(',',array_values($val))."\n"; //echo $str; fwrite($f,$str,strlen($str)); $str=''; } fclose($f);//echo phpinfo(); ?>
Output for 8.3.0 - 8.3.6
Warning: file(): open_basedir restriction in effect. File(E:\datalinks+.csv) is not within the allowed path(s): (/tmp:/in:/etc) in /in/qMWNW on line 7 Warning: file(E:\datalinks+.csv): Failed to open stream: Operation not permitted in /in/qMWNW on line 7 Warning: foreach() argument must be of type array|object, false given in /in/qMWNW on line 10 Array ( )
Output for 8.0.0 - 8.0.12, 8.0.14 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18
Warning: file(): open_basedir restriction in effect. File(E:\datalinks+.csv) is not within the allowed path(s): (/tmp:/in:/etc) in /in/qMWNW on line 7 Warning: file(E:\datalinks+.csv): Failed to open stream: Operation not permitted in /in/qMWNW on line 7 Warning: foreach() argument must be of type array|object, bool given in /in/qMWNW on line 10 Array ( )
Output for 8.0.13
Warning: file(E:\datalinks+.csv): Failed to open stream: No such file or directory in /in/qMWNW on line 7 Warning: foreach() argument must be of type array|object, bool given in /in/qMWNW on line 10 Array ( )
Output for 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.10, 7.3.32 - 7.3.33, 7.4.33
Warning: file(E:\datalinks+.csv): failed to open stream: No such file or directory in /in/qMWNW on line 7 Warning: Invalid argument supplied for foreach() in /in/qMWNW on line 10 Array ( )
Output for 7.1.25, 7.2.0 - 7.2.33, 7.3.0 - 7.3.31, 7.4.0 - 7.4.32
Warning: file(): open_basedir restriction in effect. File(E:\datalinks+.csv) is not within the allowed path(s): (/tmp:/in:/etc) in /in/qMWNW on line 7 Warning: file(E:\datalinks+.csv): failed to open stream: Operation not permitted in /in/qMWNW on line 7 Warning: Invalid argument supplied for foreach() in /in/qMWNW on line 10 Array ( )

preferences:
217.25 ms | 403 KiB | 317 Q