api - Shorten link before sending to Twitter -


I have a PHP loop that displays different headlines and links to them. Want to send with auto-generated short link The link is structured like this:

  & lt; A href = "http://twitter.com/home?status= This is Headlink {Dynamic Permalink}" & gt; Share on Twitter & lt; / A & gt;  

How can I create a brief link after creating a real permacqual on Loop?

You need to register at bit.ly and get the API key.

pref ( $ url, $ login, $ apiKey, $ format = 'xml', $ version = '2.0.1', $ history = 1) {if (substr ($ url) , 0, 7)! = 'Http: //') $ url = 'http: //'.üül; $ Bitly = 'http://api.bit.ly/shorten'; $ Param = 'version =' $ Version '& Amp; LongUrl = '. Urlencode ($ url) & Amp; Login = '. $ Login & Amp; ApiKey = '. $ ApiKey & Amp; Format = '. $ Format '& Amp; History = '$ history // url $ ch = curl_init (); Curl_setopt ($ CH, CURLOPT_URL, $ bit ly '?'. $ Absolute); Curl_setopt ($ CH, CURLOPT_RETURNTRANSFER, 1); $ Response = curl_exec ($ ch); Curl_close ($ ch); // parse based on the desired format (stroller ($ format) == 'jason') {$ json = @ json_decode ($ response, true); $ Json comeback ['result'] [$ url] ['shortUrl']; } And {$ xml = simplexml_load_string ($ response); Return 'http://bit.ly/'.xml->results->nodeKeyVal-> hash; }} // end: function

Now login login variable is your login, $ apeKey is your long URL of apiKey and $ url, you want to be less and function output less bit .ly address.

More:


Comments