PHP site 1 5/3/2017


SUBMITTED BY: canonical

DATE: May 3, 2017, 11:33 p.m.

FORMAT: PHP

SIZE: 1.8 kB

HITS: 422

  1. If you want more of my pastes visit: https://randompaste.000webhostapp.com/index.html
  2. --------------------------------------------------------------------------------------
  3. view my last post at: https://bitbin.it/N3VCFOzC/
  4. --------------------------------------------------------------------------------------
  5. <?php
  6. $api_url = "myurl";
  7. $response = file_get_contents($api_url);
  8. $my_array = json_decode($response, true);
  9. ?>
  10. //Basic CURL example
  11. // 1. Initialize
  12. $ch = curl_init();
  13. // 2. Set Options
  14. // URL to send the request to
  15. curl_setopt($ch, CURLOPT_URL, 'https://www.mysportsfeeds.com/api/feed/pull/nhl/2017-playoff/scoreboard.json?fordate=20170416');
  16. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  17. // Set method
  18. curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
  19. // Return instead of outputting directly
  20. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  21. // Set compression
  22. curl_setopt($ch, CURLOPT_ENCODING, "gzip");
  23. // Set headers
  24. curl_setopt($ch, CURLOPT_HTTPHEADER, [
  25. "Authorization: Basic " . base64_encode('user' . ":" . 'password')
  26. ]);
  27. // 3. Execute the request and fetch the response. Check for errors.
  28. $resp = curl_exec($ch);
  29. /* $gameScoreArray = $resp->scoreboard->gameScore;
  30. for ( $i=0; $i<sizeof($gameScoreArray); $i++) {
  31. echo "Away Score = " . $gameScoreArray->awayScore;
  32. echo "Home Score = " . $gameScoreArray->homeScore;
  33. } */
  34. $json=json_decode($resp,true);
  35. print_r($json);
  36. var output = "";
  37. $gameScoreArray = $resp['scoreboard']['gameScore'];
  38. for ( $i=0; $i<sizeof($gameScoreArray); $i++ ) {
  39. echo "Away Score = " . $gameScoreArray[$i]['awayScore'];
  40. echo "Home Score = " . $gameScoreArray[$i]['homeScore'];
  41. }
  42. // Close request to clear up some resources
  43. curl_close($ch);
  44. ?>

comments powered by Disqus