欢迎访问 舍力博客(www.shuyong.net)
<?php $http= strtolower(substr($_REQUEST["slurl"],0,7)); $https=strtolower(substr($_REQUEST["slurl"],0,8)); $slurl = $http=='http://'||$https=='https://' ? $_POST['slurl']:'http://'.$_POST['slurl']; function sina($type,$url){$key = '31641035'; /* 新浪APPKEY,请改成自己的 */ if($type){ $baseurl = 'http://api.t.sina.com.cn/short_url/shorten.json?source='.$key.'&url_long='.$url; }else{ $baseurl = 'http://api.t.sina.com.cn/short_url/expand.json?source='.$key.'&url_short='.$url; } $ch=curl_init(); curl_setopt($ch,CURLOPT_URL,$baseurl); curl_setopt($ch,CURLOPT_HEADER,0); curl_setopt($ch,CURLOPT_TIMEOUT,15); curl_setopt($ch,CURLOPT_RETURNTRANSFER,true); $strRes=curl_exec($ch); curl_close($ch); $arrResponse=json_decode($strRes,true); if(isset($arrResponse->error)||!isset($arrResponse[0]['url_long'])||$arrResponse[0]['url_long'] == '')return 0; if($type){ return $arrResponse[0]['url_short']; }else{ return $arrResponse[0]['url_long']; }}?>html代码
<form method="post" name="commentform" onSubmit="return SLyz();"> <div class="dwz-ms">输入你要简化的URL网址:</div> <textarea id="slurl" name="slurl"></textarea> <button type="submit"/>生成短网址</button> </form获取代码
<?php if($_POST['slurl']){?>原网址:<?php echo $_POST['slurl'].'<br />';}?> <?php if(sina(1,$slurl)!='0'){?>短网址:<?php echo sina(1,$slurl);?><?php }?>
留言/评论:◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。