Remove "http://" from URL string

admin

Administrator
Staff member
I am using a bit.ly shortener for my custom domain. It outputs
Code:
http://shrt.dmn/abc123
; however, I'd like it to just output
Code:
shrt.dmn/abc123
.

Here is my code.

Code:
//automatically create bit.ly url for wordpress widgets
function bitly()
{
  //login information
  $url = get_permalink();  //for wordpress permalink
  $login = 'UserName'; //your bit.ly login
  $apikey = 'API_KEY'; //add your bit.ly APIkey
  $format = 'json'; //choose between json or xml
  $version = '2.0.1';
  //generate the URL
  $bitly = 'http://api.bit.ly/shorten?version='.$version.'&longUrl='.urlencode($url).'&login='.$login.'&apiKey='.$apikey.'&format='.$format;

  //fetch url
  $response = file_get_contents($bitly);
//for json formating
  if(strtolower($format) == 'json')
  {
    $json = @json_decode($response,true);
    echo $json['results'][$url]['shortUrl'];
  }
  else //for xml formatting
  {
    $xml = simplexml_load_string($response);
    echo 'http://bit.ly/'.$xml->results->nodeKeyVal->hash;
  }
}