<html>
<head>
<title>t.cn url shorten</title>
</head>
<body>
<form method="post">
Long Url: <input type="text" size="100" name="url">
<input type="submit" value="Shorten">
</form>
<?php
function shortenSinaUrl($long_url){
$apiKey='****';
$apiUrl='http://api.t.sina.com.cn/short_url/shorten.json?source='.$apiKey.'&url_long='.$long_url;
$response = file_get_contents($apiUrl);
$json = json_decode($response);
return $json[0]->url_short;
#return $response;
#return $c;
}
?>
<?php
$long_url = $_REQUEST['url'];
if ($long_url) {
$tcn_url = shortenSinaUrl($long_url);
echo "Short Url is: " . $tcn_url;
echo "<br />";
echo "Long Url is: " . $long_url;
}
?>
</body>
</html>