首页 > 编程知识 正文

url地址转换,度盘短地址转换

时间:2023-05-05 16:58:08 阅读:250145 作者:1974

bit.ly 短地址转换

One of the more popular URL shortening services is Bit.ly. I've showed you how to create short URLs with TinyURL and Is.Gd, so why not show you how to create Bit.ly URLs remotely?

最受欢迎的URL缩短服务之一是Bit.ly。 我已经向您展示了如何使用TinyURL和Is.Gd创建短URL,那么为什么不向您展示如何远程创建Bit.ly URL?

PHP (The PHP) /* make a URL small */function make_bitly_url($url,$login,$appkey,$format = 'xml',$version = '2.0.1'){//create the URL$bitly = 'http://api.bit.ly/shorten?version='.$version.'&longUrl='.urlencode($url).'&login='.$login.'&apiKey='.$appkey.'&format='.$format;//get the url//could also use cURL here$response = file_get_contents($bitly);//parse depending on desired formatif(strtolower($format) == 'json'){$json = @json_decode($response,true);return $json['results'][$url]['shortUrl'];}else //xml{$xml = simplexml_load_string($response);return 'http://bit.ly/'.$xml->results->nodeKeyVal->hash;}}/* usage */$short = make_bitly_url('https://davidwalsh.name','davidwalshblog','R_96acc320c5c423e4f5192e006ff24980','json');echo 'The short URL is: '.$short; // returns: http://bit.ly/11Owun

Note that Bit.ly requires you to sign up for an account. Once you have an account, you may attain your login and URL information. I've also created functionality to recieve the shortened URL using JSON or XML.

请注意,Bit.ly要求您注册一个帐户。 拥有帐户后,您可以获取登录名和URL信息。 我还创建了使用JSON或XML接收缩短的URL的功能。

Happy shortening!

祝您起酥油!

翻译自: https://davidwalsh.name/bitly-php

bit.ly 短地址转换

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。