Example #1
0
/**
 * Bitly URL
 */
function getSmallLink($longurl, $error = 0)
{
    // Bit.ly
    $url = "http://api.bit.ly/shorten?version=2.0.1&longUrl=" . $longurl . "&login=mytour&apiKey=R_db376e66a04df853ab47af1a931fc43b&format=json&history=1";
    $s = curl_init();
    curl_setopt($s, CURLOPT_URL, $url);
    curl_setopt($s, CURLOPT_HEADER, false);
    curl_setopt($s, CURLOPT_RETURNTRANSFER, 1);
    $result = curl_exec($s);
    curl_close($s);
    $obj = json_decode($result, true);
    if (isset($obj["results"][$longurl]["shortUrl"])) {
        return $obj["results"][$longurl]["shortUrl"];
    } else {
        $error++;
        if ($error <= 2) {
            return getSmallLink($longurl, $error);
        } else {
            return $longurl;
        }
    }
}
Example #2
0
function getSmallLink($jjjj, $kkkk = 0)
{
    $llll = "http://api.bit.ly/shorten?version=2.0.1&longUrl=" . $jjjj . "&login=mytour&apiKey=R_db376e66a04df853ab47af1a931fc43b&format=json&history=1";
    $mmmm = curl_init();
    curl_setopt($mmmm, CURLOPT_URL, $llll);
    curl_setopt($mmmm, CURLOPT_HEADER, false);
    curl_setopt($mmmm, CURLOPT_RETURNTRANSFER, 1);
    $nnnn = curl_exec($mmmm);
    curl_close($mmmm);
    $oooo = json_decode($nnnn, true);
    if (isset($oooo["results"][$jjjj]["shortUrl"])) {
        return $oooo["results"][$jjjj]["shortUrl"];
    } else {
        $kkkk++;
        if ($kkkk <= 2) {
            return getSmallLink($jjjj, $kkkk);
        } else {
            return $jjjj;
        }
    }
}