(PHP 4 >= 4.0.2, PHP 5)
Raccourci une URL avec le service TinyURL.
<?php
function make_tiny_url($url)
{
$parse_url = parse_url($url);
if( empty($parse_url['scheme']) ) return FALSE;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://tinyurl.com/api-create.php?url='.urlencode($url));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
$content = curl_exec($ch);
curl_close($ch);
if( strpos($content, 'http') === FALSE )
return FALSE;
return trim($content);
}
?>
string make_tiny_url ( string $url )
Retourne l'URL raccourcie ou FALSE si une erreur est survenue.
Exemple #1 Exemple avec make_tiny_url()
<?php $url = "http://seebz.net/"; $url = make_tiny_url($url); echo $url; // http://tinyurl.com/y9kvrsq ?>
Commentaire(s)
Poster un commentaire