开放的编程资料库

当前位置:我爱分享网 > PHP教程 > 正文

使用 PHP 创建一个 Is.Gd URL

Is.Gd 是一种 URL 缩短服务,很像 TinyURL。使用 PHP 的 cURL 库,您可以轻松地即时创建缩短的 URL。

PHP

//gets the data from a URL  
function get_isgd_url($url)  
{  
	//get content
	$ch = curl_init();  
	$timeout = 5;  
	curl_setopt($ch,CURLOPT_URL,'http://is.gd/api.php?longurl='.$url);  
	curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);  
	curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);  
	$content = curl_exec($ch);  
	curl_close($ch);
	
	//return the data
	return $content;  
}

//uage
$new_url = get_isgd_url('https://davidwalsh.name/php-imdb-information-grabber');

“is.gd”比“tinyurl.com”短得多,因此如果您需要 URL 尽可能短,请使用此方法。

未经允许不得转载:我爱分享网 » 使用 PHP 创建一个 Is.Gd URL

感觉很棒!可以赞赏支持我哟~

赞(0) 打赏