Skip to content

Instantly share code, notes, and snippets.

Created March 2, 2014 07:00
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save Nickfost/9302984 to your computer and use it in GitHub Desktop.
Bitly Function
//explode $data into a $line and explode line into a $word and check if it's a url then pass it bitly and return that url
function bitly($data){
$token = ""; // you must add your api token here
//break into line by line
$linearray = explode("\n",$data);
$linei = 0;
foreach($linearray as $line){
$wordarray = explode(" ",$line);
$wordi = 0;
foreach($wordarray as $word){
if(filter_var($word, FILTER_VALIDATE_URL)){
$api = "".$token."&URI=".$word;
$apidata = json_decode(file_get_contents($api), true);
$newwordarray[$wordi] = "".$apidata['data']['hash'];
$newwordarray[$wordi] = $word;
//echo "Looks like ".$word." Returned an error ".$apidata['status_txt']."<br /> \n";
$newwordarray[$wordi] = $word;
$newlinearray[$linei] = implode(" ", $newwordarray);
$finaldata = implode("\n",$newlinearray);
return $finaldata;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment