title: Convert url to bit.ly
body: <p>For some reason, i can't seem to get my function to convert all url's to bit.ly's. Please keep it so that it still converts url's to hyperlinks. Thanks and Please help!!!</p>
  
  <pre><code>function get_short_url(long_url, login, api_key, func)
  {
      $.getJSON(
          "http://api.bitly.com/v3/shorten?callback=?", 
          { 
              "format": "json",
              "apiKey": api_key,
              "login": login,
              "longUrl": long_url
          },
          function(response)
          {
              func(response.data.url);
          }
      );
  }
  
  var login = "[mylogin]";
  var api_key = "[my api]";
  var long_url = text;
  
  get_short_url(long_url, login, api_key, function(short_url) {
      console.log(short_url);
  });
  
    urlify = function (text) {
      var urlRegex = /(https?:\/\/[^\s]+)/g;
      return text.replace(urlRegex, function(short_url) {
        return '&lt;a href="' + short_url + '" target="_blank"&gt;' + short_url + '&lt;/a&gt;';
      })
      // or alternatively
      // return text.replace(urlRegex, '&lt;a href="$1"&gt;$1&lt;/a&gt;')
    }
  </code></pre>