PHP使用 tinyurl 生成短网址

使用 tinyurl 生成短网址

function get_tiny_url($url) 
{ 
    $ch = curl_init(); 
    $timeout = 5; 
    curl_setopt($ch,CURLOPT_URL,'http://tinyurl.com/api-create.php?url='.$url); 
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); 
    curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout); 
    $data = curl_exec($ch); 
    curl_close($ch); 
    return $data; 
}


语法:

<?php
$url = "http://blog.koonk.com/2015/07/Hello-World";
$tinyurl = get_tiny_url($url);
echo $tinyurl;
?>

分类:
|  标签 :
0 0 vote
Article Rating
Subscribe
提醒
guest
0 评论
Inline Feedbacks
View all comments