A PHP Class file that creates an object and related methods for accessing the Chicago Transit Authority's three web-based Application Programming Interfaces for Bus, Train ('El') and Service information
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.


This CTA class file is an API wrapper for interfacing with the Chicago Transit Authority's three web-based Application Programming Interfaces for Bus, Train ('El') and Alerts related information. 

Due to the evolution of the CTA's API interfaces, there are three distinct APIs, one for Bus, Train and  Customer Alert information. As a result there are three distinct URI endpoints and two distinct API keys. 

This class brings all three APIs together into one object with related methods for accessing Bus, Train and Customer Alert information.

However, there is no requirement that both an Bus and Train API key are needed to use this class file. That is while this class file helps to unify the three distinct APIs together for a PHP developer, this class can also be used to interface with just the Bus, Train or Customer Alert API and nothing else.  

More information about the CTA's APIs, including terms of use and how to request API Keys, can be found at: http://www.transitchicago.com/developers/default.aspx

This class file depends on PHP support of Client URL Library (cURL) and SimpleXML.

PHP's cURL functions are themselves built on libcurl, a library that enables support for a number of different network protocols. Information on how to build and enable cURL support in PHP can be found at: http://php.net/manual/en/book.curl.php

SimpleXML is a PHP extension that provides a simple and easily toolset for managing XML by converting XML data into an object. Similar to cURL, SimpleXML is itself dependent on libxml. Information on how to add SimpleXML can be found at: http://php.net/manual/en/book.simplexml.php

To install and use this class and its functions, simply copy the class.cta.php file into a directory that is accessible by your PHP script and include the file using the include (or similar require) function. Example:

	// Load the class file in our current directory
	include_once( 'class.cta.php' );
Once the class file has been loaded, the next step is to instantiate the class:
	$transit = new CTA( 'YOUR-TRAIN-API_KEY_HERE', 'YOUR-BUS-API-KEY-HERE', false );
Note that you will need to provide your own API keys when initializing the object. If no valid API keys are provided the only methods that will return valid information are the Customer Alert based methods for system status information (statusRoutes and statusAlerts) as that specific API does not require an API key. 

To invoke a method simple use the object and related function, providing an additional information as parameters:

	// Get an array result of all stops for route 81 in going East Bound
	$81EastBoundStops = $transit->busGetStops( '81', 'East Bound' ));
Further examples can be found in the provided example.php file.