tinyurl_用PHP创建TinyURL

tinyurl

TinyURL is an awesome service. For those who don't know what TinyURL is, TinyURL allows you to take a long URL like "https://davidwalsh.name/jquery-link-nudging" and turn it into "http://tinyurl.com/67c4se". Using the PHP and TinyURL API, you can create these tiny URLs on the fly!

TinyURL是一项很棒的服务。 对于那些不知道TinyURL是什么的人,TinyURL允许您采用长网址,例如“ https://davidwalsh.name/jquery-link-nudging”,并将其转换为“ http://tinyurl.com/67c4se” 。 使用PHP和TinyURL API,您可以即时创建这些微小的URL!

PHP (The PHP)


//gets the data from a URL  
function get_tiny_url($url)  {  
	$ch = curl_init();  
	$timeout = 5;  
	curl_setopt($ch,CURLOPT_URL,'http://tinyurl.com/api-create.php?url='.$url);  
	curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);  
	curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);  
	$data = curl_exec($ch);  
	curl_close($ch);  
	return $data;  
}

//test it out!
$new_url = get_tiny_url('https://davidwalsh.name/php-imdb-information-grabber');

//returns http://tinyurl.com/65gqpp
echo $new_url


Simply provide the URL and you'll received the new, tiny URL in return. If you use Twitter, you'll have noticed that Twitter automates tiny URL creation for URLs in tweets.

只需提供URL,您就会收到新的微小URL作为回报。 如果您使用Twitter,您会注意到Twitter自动为推文中的URL自动创建微小的URL。

翻译自: https://davidwalsh.name/create-tiny-url-php

tinyurl

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值