PHPでbit.lyのURLを作成

  • 2012.07.21
  • 2012.07.21
  • Web

bit.ly API+PHPを使って短縮URLを作成する方法をメモ

<?php
    $url = “https://www.yahoo.co.jp”;

    $api_url = “https://api.bitly.com/v3/shorten?”.
           “login=bit.lyのユーザ―名“.
           “&apiKey=bit.lyのAPIキー“.
           “&longUrl=”.urlencode($url).
           “&format=xml”;
    $xml = simplexml_load_file($api_url);
    echo $xml->data->url;
?>