Created
December 14, 2019 12:31
-
-
Save hiroshikuze/b7c1d248f00cdc52608ba11b7a01a08a to your computer and use it in GitHub Desktop.
bitlyによる短縮URL作成例(2010/04/11現在)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$strURLfull = '[[短縮URLにしたいURLを指定してください]]'; | |
$strBitlyResultArr = file("http://api.bit.ly/shorten?version=2.0.1&longUrl=".urlencode($strURLfull)."&login=[[ログインID]]&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