Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function updateTerminal2() {
- $html = file_get_contents('https://www.manila-airport.net/naia-arrivals-terminal-2'); //get the html returned from the following url
- $tableData = array();
- $pokemon_doc = new \DOMDocument();
- libxml_use_internal_errors(TRUE); //disable libxml errors
- if (!empty($html)) { //if any html is actually returned
- $pokemon_doc->loadHTML($html);
- libxml_clear_errors(); //remove errors for yucky html
- $pokemon_xpath = new \DOMXPath($pokemon_doc);
- $pokemon_row = $pokemon_xpath->query('//div[contains(@id,"flight_detail")] and @class!="adsense"');
- $tempData = array();
- $data = array();
- $processData = array();
- $count = 0;
- $toPushItem = new \StdClass;
- foreach ($pokemon_row as $key => $row) {
- $data[] = $row->nodeValue;
- // unset($data[0]);
- // unset($data[1]);
- // unset($data[2]);
- // unset($data[3]);
- // unset($data[4]);
- }
- end($data);
- $key = key($data);
- for ($j = 2; $j < $key; $j +=3) {
- $count++;
- $tempDatas[] = $data[$j];
- for ($i = 2; $i != $key; $i++) {
- //$tempDatas[] = $data[$i];
- }
- // if ($count == 2) {
- //
- // $toPushItem = $tempData[0];
- //// $toPushItem->Carrier = $tempData[1];
- //// $toPushItem->Destination = $tempData[2];
- //// $toPushItem->Departure = $tempData[3];
- //// $toPushItem->Status = $tempData[4];
- // $processData[] = $toPushItem;
- //
- // $count = 0;
- // $tempData = array();
- // $toPushItem = new \StdClass;
- // }
- }
- foreach ($tempDatas as $key => $data2){
- // if ($key == 25) continue;
- $buffer = str_replace(array("\n", ), ',', $data2);
- $buffer = str_replace(array(",,,",",," ), ',', $buffer);
- $string = trim($buffer,",");
- $x = preg_replace('/\s*,\s*/', ',', $string);
- $myArray[] = explode(',', $x);
- // $buffer = str_replace(array("\n", ), ',', $data2);
- // $buffer = str_replace(array(",,,",",," ), ',', $buffer);
- // $string = trim($buffer,",");
- //
- // $x = preg_replace('/\s*,\s*/', ',', $string);
- //
- // $myArray[] = explode(',', $x);
- }
- // print_r($myArray);exit;
- //
- $json = json_encode($myArray);
- $array = json_decode($json, true);
- //
- print_r($array);exit;
- $mostRecent = 0;
- foreach ($array as $Date) {
- // $name = str_replace('/','_',$Date['DrawDate']);
- // print_r($name);exit;
- //
- // $name = str_replace('/','_',$Date["3"]);
- // print_r($name);exit;
- $originalDate = $Date["3"];
- $newDate = date("Y-m-d", strtotime($originalDate));
- $ByDate[$newDate][] = $Date;
- $lastDate[] = $newDate;
- $mostRecent = array('lastDate' => max(array_unique($lastDate)));
- // $ByDate[$name][] = $Date;
- }
- $day = $mostRecent["lastDate"];
- $lastArray = [];
- foreach ($ByDate as $final => $value) {
- $lastArray[$final] = $value;
- }
- $data = json_encode($lastArray[$day]);
- $data2 = json_encode($mostRecent);
- // print_r(max($mostRecent));exit;
- $url = "https://pcso-lotto-ph.firebaseio.com/results2/t3/$day.json";
- $ch = curl_init($url);
- curl_setopt($ch, CURLOPT_HTTPHEADER, array(
- 'Content-Type: application/json',
- 'Content-Length: ' . strlen($data))
- );
- curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
- curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
- $jsonResponse = curl_exec($ch);
- if (curl_errno($ch)) {
- echo 'Curl error: ' . curl_error($ch);
- }
- curl_close($ch);
- $url2 = "https://pcso-lotto-ph.firebaseio.com/last2.json";
- $ch2 = curl_init($url2);
- curl_setopt($ch2, CURLOPT_HTTPHEADER, array(
- 'Content-Type: application/json',
- 'Content-Length: ' . strlen($data2))
- );
- curl_setopt($ch2, CURLOPT_CUSTOMREQUEST, "PUT");
- curl_setopt($ch2, CURLOPT_POSTFIELDS, $data2);
- curl_setopt($ch2, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($ch2, CURLOPT_SSL_VERIFYHOST, 0);
- curl_setopt($ch2, CURLOPT_SSL_VERIFYPEER, 0);
- $jsonResponse2 = curl_exec($ch2);
- if (curl_errno($ch2)) {
- echo 'Curl error: ' . curl_error($ch2);
- }
- curl_close($ch2);
- }
- } //END TERMINAL 2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement