PHP PHP tiny url编码和解码功能

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PHP PHP tiny url编码和解码功能相关的知识,希望对你有一定的参考价值。

function doShortURL($url) {
	$short_url= file_get_contents('http://tinyurl.com/api-create.php?url=' . urlencode( $url ) );
	return $short_url;
}


function doShortURLDecode($url) {
	$ch = @curl_init($url);
	@curl_setopt($ch, CURLOPT_HEADER, TRUE);
	@curl_setopt($ch, CURLOPT_NOBODY, TRUE);
	@curl_setopt($ch, CURLOPT_FOLLOWLOCATION, FALSE);
	@curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
	$response = @curl_exec($ch);
	preg_match('/Location: (.*)\n/', $response, $a);
	if (!isset($a[1])) return $url;
	return $a[1];
}

以上是关于PHP PHP tiny url编码和解码功能的主要内容,如果未能解决你的问题,请参考以下文章