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: 165 All time: 8,885 This week: 111Up
Version License PHP version Categories
xmlstats 1.0.2MIT/X Consortium ...5.6PHP 5, Statistics, Games, Web services


This class can retrieve statistics from NBA and MLB API.

It sends HTTP requests to 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 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: 405 Up46 in United States United States Up
Innovation award
Innovation award
Nominee: 3x




// form
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;
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">
        <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>
        <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>
        <td><label for="date">Date:</label></td>
        <td><input name="date" id="date" type="text" placeholder="YYYYmmdd" /></td>
        <td><label for="id" title="team_id, event_id, category_id">ID:</label></td>
        <td><input name="id" id="id" type="text" /></td>
<br />
<input type="submit" value="Submit" />

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

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

'<pre>'. print_r($arr, 1) .'</pre>';

  Files folder image Files  
File Role Description
Files folder imageXMLstats (1 file)
Accessible without login Plain text file 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  
This week:0
All time:8,885
This week:111Up