getShort($yourLongUrl); // echo $mbit->getLong($bitlyShortUrl); Author: Carlo Perassi Version: 0.1 Home: http://perassi.org/2010/07/01/php5-class-for-bit-ly-api/ License: GNU General Public License Version 3 (http://www.gnu.org/licenses/gpl.html) */ class BitlyWalsh { private $_apiKey; private $_login; private $_timeout; function __construct($login, $apiKey) { $this->_login = $login; $this->_apiKey = $apiKey; $this->_timeout = 5; } private function _curlGetResult($url) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $this->_timeout); $data = curl_exec($ch); curl_close($ch); return $data; } public function getLong($url, $format = 'txt') { $connectURL = 'http://api.bit.ly/v3/expand?login=' . $this->_login . '&apiKey=' . $this->_apiKey . '&shortUrl=' . urlencode($url) . '&format=' . $format; return $this->_curlGetResult($connectURL); } public function getShort($url, $format = 'txt') { $connectURL = 'http://api.bit.ly/v3/shorten?login=' . $this->_login . '&apiKey=' . $this->_apiKey . '&uri=' . urlencode($url) . '&format=' . $format; return $this->_curlGetResult($connectURL); } }