NomadicWarrior

Arrays

Apr 27th, 2020
30
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. <?php
  2.  
  3. // ini_set('display_errors', 1);
  4. // ini_set('display_startup_errors', 1);
  5. // error_reporting(E_ALL);
  6.  
  7. $htmlContent = file_get_contents("https://en.wikipedia.org/wiki/Template:2019–20_coronavirus_pandemic_data");
  8.  
  9. $DOM = new DOMDocument();
  10. $DOM->loadHTML($htmlContent);
  11.  
  12. $Header = $DOM->getElementsByTagName('th');
  13. $Detail = $DOM->getElementsByTagName('td');
  14.  
  15. //#Get header name of the table
  16. foreach($Header as $NodeHeader)
  17. {
  18. $aDataTableHeaderHTML[] = trim($NodeHeader->textContent);
  19. }
  20. $th3 = $aDataTableHeaderHTML;
  21. $th2 = array_slice($th3, 11);
  22. $th1 = array_slice($th2, 0, 435);
  23. $th = array_values(array_filter($th1, 'strlen'));
  24.  
  25. //print_r($th); //- Only country names
  26.  
  27.  
  28. //#Get row data/detail table without header name as key
  29. foreach($Detail as $sNodeDetail)
  30. {
  31. $aDataTableDetailHTML[] = trim($sNodeDetail->textContent);
  32. }
  33.  
  34. $td1 = array_slice($aDataTableDetailHTML, 0, 871);
  35. $td = array_chunk($td1, 4);
  36.  
  37. //print_r($td); // - Only country results without names
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44. ?>
Add Comment
Please, Sign In to add comment