Advertisement
NomadicWarrior

Table Parse

Apr 26th, 2020
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. <?php
  2. $String = file_get_contents('https://en.wikipedia.org/wiki/Template:2019–20_coronavirus_pandemic_data');
  3.  
  4. function Cases($sp1, $sp2, $sp3)
  5. {
  6. $num1 = strpos($sp1, $sp2);
  7. if($num1 === false) return 0;
  8.  
  9. $num2 = substr($sp1, $num1);
  10. $result = strip_tags(substr($num2, 0, strpos($num2, $sp3)));
  11.  
  12. // print_r($result);
  13. function multiexplode ($delimiters,$string) {
  14.  
  15. $ready = str_replace($delimiters, $delimiters[0], $string);
  16. $launch = explode($delimiters[0], $ready);
  17. return $launch;
  18. }
  19.  
  20. $res = multiexplode(array('&#8205;','&#91;','&#93;'), $result);
  21.  
  22. $r = array_slice($res, 6);
  23. $t = array_slice($r, 0, 575);
  24. //$st = strip_tags($t, ['<br>']);
  25.  
  26. foreach ($t as $key=>$item)
  27. {
  28. echo "$key => $item <br>";
  29. }
  30.  
  31. }
  32.  
  33. Cases($String, '<tr>', '</tbody>');
  34. ?>
  35.  
  36.  
  37. <!DOCTYPE html>
  38. <html>
  39. <head>
  40. <style>
  41. #customers {
  42. font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
  43. border-collapse: collapse;
  44. width: 100%;
  45. }
  46.  
  47. #customers td, #customers th {
  48. border: 1px solid #ddd;
  49. padding: 8px;
  50. }
  51.  
  52. #customers tr:nth-child(even){background-color: #f2f2f2;}
  53.  
  54. #customers tr:hover {background-color: #ddd;}
  55.  
  56. #customers th {
  57. padding-top: 12px;
  58. padding-bottom: 12px;
  59. text-align: left;
  60. background-color: red;
  61. color: white;
  62. }
  63. </style>
  64. </head>
  65. <body>
  66.  
  67. <table id="customers">
  68. <tr>
  69. <th>Countries</th>
  70. <th>Cases</th>
  71. <th>Deaths</th>
  72. <th>Recov.</th>
  73. </tr>
  74. <tr>
  75. <td>Contents</td>
  76. </tr>
  77. <tr>
  78. <td>Contents</td>
  79. </tr>
  80. <tr>
  81. <td>Contents</td>
  82. </tr>
  83. </table>
  84.  
  85. </body>
  86. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement