Skip to content

Instantly share code, notes, and snippets.

@hiroshikuze
Created December 14, 2019 12:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hiroshikuze/b7c1d248f00cdc52608ba11b7a01a08a to your computer and use it in GitHub Desktop.
Save hiroshikuze/b7c1d248f00cdc52608ba11b7a01a08a to your computer and use it in GitHub Desktop.
bitlyによる短縮URL作成例(2010/04/11現在)
<?php
$strURLfull = '[[短縮URLにしたいURLを指定してください]]';
$strBitlyResultArr = file("http://api.bit.ly/shorten?version=2.0.1&amp;longUrl=".urlencode($strURLfull)."&amp;login=[[ログインID]]&amp;apiKey=[[api key]]");
$strBitlyResult = "";
foreach($strBitlyResultArr as $strI) {
if(strpos($strI, "shortCNAMEUrl") > 0) {
$strBitlyResultArr = sscanf(trim($strI),'"shortCNAMEUrl": "%s",');
if(strlen($strBitlyResultArr) > 0) {
$strBitlyResult = str_replace('",','',$strBitlyResultArr[0]);
break;
}
}
}
if(strlen($strBitlyResult) == 0) { $strBitlyResult = $strURLfull; }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment