PageRenderTime 52ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/simplehtmldom/index.php

https://github.com/tomascarlsson/API
PHP | 74 lines | 49 code | 9 blank | 16 comment | 5 complexity | 3b215a67a0fd080003b7bfb0140f8bb8 MD5 | raw file
  1. <!doctype html>
  2. <html lang="sv">
  3. <head>
  4. <title>Test av API, koder m.m.</title>
  5. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  6. <link rel="stylesheet" type="text/css" href="style.css" />
  7. </head>
  8. <body>
  9. <?php
  10. error_reporting(E_ALL);
  11. // Test API, Webscraping Glenn Miller Café program
  12. // PHP Simple HTML DOM Parser - bibliotek - http://simplehtmldom.sourceforge.net/manual_api.htm
  13. include('simplehtmldom_1_5/simple_html_dom.php');
  14. // Create a DOM object from a URL or file
  15. $htmlglennMillerProgram= file_get_html('http://www.glennmillercafe.com/program/');
  16. // Alla artiklar med skivrecensioner
  17. foreach($htmlglennMillerProgram->find('div.menu-item') as $glennSpelning) {
  18. //echo $glennSpelning;
  19. $bandNamn = $glennSpelning->find('p.menu-thingy', 0);
  20. if (stristr($bandNamn, ':') == TRUE){
  21. //echo stristr($bandNamn, ':', true); // Tar fran allt i strängen innan kolona
  22. echo $bandNamn->find('text', 0);
  23. // "<h5>". $glennSpelning->find('h4.menu-titel', 0) ."</h5>";
  24. $strDateInfo = $glennSpelning->find('h4.menu-titel', 0);
  25. $arrDateInfo = explode(" ", $strDateInfo);
  26. //echo "<pre>";
  27. //print_r($arrDateInfo);
  28. //echo "</pre>";
  29. $currDay = $arrDateInfo[4];
  30. $currTime = end($arrDateInfo);
  31. //$currMonth = $arrDateInfo[5];
  32. $months = array(1=>"januari", 2=>"februari", 3=>"mars", 4=>"april", 5=>"maj", 6=>"juni", 7=>"juli", 8=>"augusti", 9=>"september", 10=>"oktober", 11=>"november", 12=>"december");
  33. //print_r($months);
  34. $newArray = array_intersect($arrDateInfo, $months); // Matchar värden från i två arrayer och sparar dem i ny array.
  35. foreach($newArray as $currMonth){
  36. for($i=1; $i<count($months); $i++) {
  37. if($currMonth == $months[$i]) // få ut nyckelväret
  38. $keyMonth = array_search($currMonth, $months);
  39. }
  40. $date = "2012-".$keyMonth."-".$currDay;
  41. $time = $currTime;
  42. //echo 2012-10
  43. // datum 2012-10-01 2012-$months[]
  44. // Tid 20:00
  45. $spelningarGlennMiller[] = array(
  46. //'id' => $row['id'],
  47. 'bandnamn' => stristr($bandNamn, ':', true),
  48. 'genre' => 'jazz',
  49. 'info' => 'Se hemsidan',
  50. 'scen' => 'Glenn Miller Café',
  51. 'datum' => $date,
  52. 'tid' => $time,
  53. 'intrade' => 'Fri',
  54. 'alder' => '18',
  55. 'web' => 'http://www.glennmillercafe.com/program'
  56. );
  57. } // end foreach
  58. } // end if
  59. } // end foreach
  60. echo "<pre>";
  61. print_r ($spelningarGlennMiller) ;
  62. echo "</pre>";
  63. ?>
  64. </body>
  65. </html>