글 짧은주소 표시하기
https://hoy.kr 의 API를 이용합니다.
1. https://hoy.kr 에 회원가입후 API Key를 받아옵니다
2.
[code]
<?php
$link = "https://{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}";
?>
<?php/**** Sample PHP Function ***/function shorten($url, $custom = "", $format = "json") { $api_url = "https://hoy.kr/api/?key=API키";$api_url .= "&url=".urlencode(filter_var($url, FILTER_SANITIZE_URL));if(!empty($custom)){$api_url .= "&custom=".strip_tags($custom);}$curl = curl_init();curl_setopt_array($curl, array(CURLOPT_RETURNTRANSFER => 1,CURLOPT_URL => $api_url));$Response = curl_exec($curl);curl_close($curl);if($format == "text"){$Ar = json_decode($Response,TRUE);if($Ar["error"]){return $Ar["msg"];}else{return $Ar["short"];}}else{return $Response;}}?>
[/code]
API key를 넣은 이 php를 어딘가에 위치해줍니다.
3.
[code]
<?php echo shorten($link);?>
[/code]
를 주소가 표시되고 싶은곳에 넣어줍니다.
끝!
|
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기
댓글 10개
이렇게http://www.selfdaet24.com으로 끝나는 짧은주소 이렇게는 안되남요