1

一篇来自老外的博客:

Create Short URLS Using U.Nu
+---------------------------------------------------------------------------------------+
I was recently referred to another URL shortening website called u.nu. As for as shorting services go,u.nu seems to have the field beat as far as the shorts base URL. If you're really intent on creating the shortest possible URLs,look no further than u.nu's API.

我最近到另一个缩短网址的u.nu尽可能缩短服务,u.n有可能在最短的时间里面击败基础URL.如果你真的有意在最短的网址,不要再比u.nu的API.

+---------------------------------------------------------------------------------------+
THE PHP

function get_unu_url($url){

$url='http://u.nu/unu-api-simple?url='.urlencode($url);

$ch=curl_init();
$timeout=5;

curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);
$url=curl_exec($ch);

curl_close($ch);

return trim($url);
}

$shorturl=get_unu_url('http://davidwalsh.name');
//return http://u.nu.92e

posted @ 2012-09-27 12:03  sgsheg  阅读(144)  评论(0编辑  收藏  举报