Url to TinyUrl Function

Code

I needed to transform some long urls into tiny ones :p

Figured I’d post something up here that may be useful to someone else.

Code was updated.

/**
 * Get TinyUrl for $url
 *
 * @param string $url Must be a valid url
 */
function getTinyUrl($url) {
	if (! $url) {
		return false;
	}

	if (strlen ( $url ) < 30) {
		return $url;
	}

	$response = file_get_contents ( 'http://tinyurl.com/api-create.php?url=' . $url );

	return ($response) ? $response : $url;
}

Leave a Reply

You must be logged in to post a comment.