Advertisement
Guest User

Untitled

a guest
Apr 21st, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.45 KB | None | 0 0
  1. $html = file_get_contents('https://www.manila-airport.net/naia-departures-terminal-1'); //get the html returned from the following url
  2. $tableData = array();
  3. $pokemon_doc = new \DOMDocument();
  4. libxml_use_internal_errors(TRUE); //disable libxml errors
  5.  
  6.  
  7. if (!empty($html)) { //if any html is actually returned
  8. $pokemon_doc->loadHTML($html);
  9. libxml_clear_errors(); //remove errors for yucky html
  10. $pokemon_xpath = new \DOMXPath($pokemon_doc);
  11.  
  12. $pokemon_row = $pokemon_xpath->query('//div[contains(@id,"flight_detail")]');
  13.  
  14.  
  15. $tempData = array();
  16. $data = array();
  17. $processData = array();
  18. $count = 0;
  19. $toPushItem = new \StdClass;
  20. foreach ($pokemon_row as $key => $row) {
  21.  
  22. $data[] = $row->nodeValue;
  23. // unset($data[0]);
  24. // unset($data[1]);
  25. // unset($data[2]);
  26. // unset($data[3]);
  27. // unset($data[4]);
  28.  
  29. }
  30.  
  31.  
  32. end($data);
  33. $key = key($data);
  34.  
  35. for ($i = 0; $i != $key; $i++) {
  36. $count++;
  37. $tempData[] = $data[$i];
  38.  
  39. for ($j = 2; $j < $key; $j +=3) {
  40.  
  41. $tempDatas[] = $data[$j];
  42.  
  43. }
  44.  
  45.  
  46. // if ($count == 2) {
  47. //
  48. // $toPushItem = $tempData[0];
  49. //// $toPushItem->Carrier = $tempData[1];
  50. //// $toPushItem->Destination = $tempData[2];
  51. //// $toPushItem->Departure = $tempData[3];
  52. //// $toPushItem->Status = $tempData[4];
  53. // $processData[] = $toPushItem;
  54. //
  55. // $count = 0;
  56. // $tempData = array();
  57. // $toPushItem = new \StdClass;
  58. // }
  59. }
  60.  
  61.  
  62. foreach ($tempDatas as $key => $data2){
  63. $buffer = str_replace(array("\n", ), ',', $data2);
  64. $buffer = str_replace(array(",,,",",," ), ',', $buffer);
  65. $string = trim($buffer,",");
  66.  
  67. $x = preg_replace('/\s*,\s*/', ',', $string);
  68.  
  69. $myArray[] = explode(',', $x);
  70.  
  71.  
  72.  
  73. }
  74.  
  75. print_r($myArray);exit;
  76.  
  77. $json = json_encode($processData);
  78. $array = json_decode($json, true);
  79.  
  80. print_r($tempData);exit;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement