PHP Classes

PHP NBA API and MLB Stats: Retrieve statistics from NBA and MLB API

Recommend this page to a friend!
  Info   View files Example   View files View files (3)   DownloadInstall with Composer Download .zip   Reputation   Support forum (1)   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 166 This week: 1All time: 8,885 This week: 560Up
Version License PHP version Categories
xmlstats 1.0.2MIT/X Consortium ...5.6PHP 5, Statistics, Games, Web services
Description 

Author

This class can retrieve statistics from NBA and MLB API.

It sends HTTP requests to erikberg.com API Web server to retrieve endpoints and make API calls to retrieve several types of statistics about NBA (National Basketball Association) and MLB (Major League Baseball) sports events.

Currently it can retrieve information about: events, roster, standings, teams, results, boxscore, wildcard, draft, leaders, daily leaders and team stats.

Innovation Award
PHP Programming Innovation award nominee
March 2017
Number 5


Prize: One ebook of choice by Packt
NBA and MLB are United States associations that organize professional championships of popular sports that are basketball and baseball.

This package can retrieve several types of statistics about NBA and MLB from erikberg.com API.

Manuel Lemos
Picture of Matthew Boyle
  Performance   Level  
Name: Matthew Boyle <contact>
Classes: 6 packages by
Country: United States United States
Age: ???
All time rank: 1963276 in United States United States
Week rank: 416 Up46 in United States United States Up
Innovation award
Innovation award
Nominee: 3x

Example

<?
error_reporting
(E_ERROR | E_WARNING | E_PARSE);
ini_set('display_errors',true);

echo
'<html>
<body>'
;

if(
$_SERVER['REQUEST_METHOD'] != 'POST' )
{
   
// form
?>
<style>
td {
    border: 1px solid #000;
}
td:first-child {
    text-align: right;
}
td label {
    padding-right: 10px;
    font-weight: bold;
}
td input,
td select {
    margin-left: 5px;
}
</style>
The form below can request teams or standing* for either sport which don't require an API token.<br />
It can also request data that does require a token. If you have a valid token you may edit this file to utilize it.<br /><br />
* standings will require a token if a date is specified.
<form method="post">
<table>
    <tr>
        <td><label for="sport">Sport:</label></td>
        <td><select name="sport" id="sport">
            <option value="">Both / None</option>
            <option value="mlb">MLB Baseball</option>
            <option value="nba">NBA Basketball</option>
        </select></td>
    </tr><tr>
        <td><label for="endpoint">Information:</label></td>
        <td><select name="endpoint" id="endpoint">
            <option value="me">API account</option>
            <option value="events">Events</option>
            <option value="standings">Standings</option>
            <option value="leaders">Leaders</option>
            <option value="boxscore">Box Score</option>
        </select></td>
    </tr><tr>
        <td><label for="date">Date:</label></td>
        <td><input name="date" id="date" type="text" placeholder="YYYYmmdd" /></td>
    </tr><tr>
        <td><label for="id" title="team_id, event_id, category_id">ID:</label></td>
        <td><input name="id" id="id" type="text" /></td>
    </tr>
</table>
<br />
<input type="submit" value="Submit" />
</form>
<?
}
else
{
    include(
'XMLstats/xmlstats.class.php');

   
$stats = new XMLstats();
   
$params = [];
    foreach(
$_POST as $k => $v){
        if(
$k != 'endpoint' && !empty($v))
           
$params[$k] = $v;
    }
   
$data = $stats->getData($_POST['endpoint'],$params);

   
$arr = json_decode($data,1);
   
$arr['headers'] = $stats->getResponseHeader();

    echo
'<pre>'. print_r($arr, 1) .'</pre>';
}
?>
</body>
</html>


  Files folder image Files  
File Role Description
Files folder imageXMLstats (1 file)
Accessible without login Plain text file about.md Doc. description
Accessible without login Plain text file example.php Example example

  Files folder image Files  /  XMLstats  
File Role Description
  Plain text file xmlstats.class.php Class XMLstats class file

 Version Control Unique User Downloads Download Rankings  
 0%
Total:166
This week:1
All time:8,885
This week:560Up