(PHP 4 >= 4.0.2, PHP 5)
Raccourci une URL avec le service Google URL Shortener.
<?php
function make_googl_url($url)
{
$parse_url = parse_url($url);
if( empty($parse_url['scheme']) ) return FALSE;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://ggl-shortener.appspot.com/?url='.urlencode($url));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
$content = curl_exec($ch);
curl_close($ch);
preg_match('`"(http[^"]+)"`', $content, $m);
if( !isset($m[1]) ) return FALSE;
return $m[1];
}
?>
string make_googl_url ( string $url )
Retourne l'URL raccourcie ou FALSE si une erreur est survenue.
Exemple #1 Exemple avec make_googl_url()
<?php $url = "http://seebz.net/"; $url = make_googl_url($url); echo $url; // http://goo.gl/zZb2 ?>
Commentaire(s)
Poster un commentaire