views:

188

answers:

2

Hi guys,

   <?php 
    include('bitly.php'); 
    $bitly = new bitly('myusername', 'myapikey'); 
    print $bitly->shorten('http://www.google.com');
    ?> 

WORKING!!!

$currenturl = (!empty($_SERVER['HTTPS'])) ? "https://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'] : "http://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
include('bitly.php'); 
$bitly = new bitly('myusername', 'myapikey'); 
print $bitly->shorten($currenturl);

WORKING!!!

include('bitly.php'); 
$currenturl = (!empty($_SERVER['HTTPS'])) ? "https://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'] : "http://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
$url = "somehashtag"
$shareurl = $currenturl . '#' . $url;

$bitly = new bitly('myusername', 'myapikey'); 
print $bitly->shorten($shareurl);

NOT WORKING!!! Any idea why? If i print out the $shareurl i can see that it's a completely normal url that i could paste onto the normal bit.ly website.

I don't get it! Any ideas? Would be great if you could help me!

A: 

I think you need to urlencode your hash character. Try

$shareurl = $currenturl . urlencode('#') . $url;
JacobM
THANK YOU VERY MUCH!
A: 

I've got one more question. I'm not much of an php expert, but I guess if I'm calling the bitly service with this line $bitly->shorten($shareurl); a few times it's not very performative.

$bitly = new bitly('myusername', 'myapikey'); 
print $bitly->shorten($shareurl);

Can't i just save this bitly request to a var and paste it where i need it. For instance I'm having a few sharing links where i'm always using this bitly link.

$output .= "&hellip; share this link <a href=" . 'mailto:?subject=hello&amp;body=' . $bitly->shorten($shareurl) . ">via email?</a> <a href=" . 'http://www.facebook.com/sharer.php?u='. $bitly->shorten($shareurl) . '?t=hello' .">on facebook?</a> <a href=" . 'http://twitter.com/home?status=' . $bitly->shorten($shareurl) . ">on twitter?</a>";

Is there a better way to this? Instead of doing the bitly request three times?

Of course. Just do `$shortenedUrl = $bitly->shorten($shareurl);` and use `$shortenedUrl` in the output concatenation.
JacobM