May 3, 2010

How to enable PHP JSON on Gentoo server?

URL shortener API를 php에서 사용해보려고 하다가 만난 삽질들인데...

CentOS 에서는
pecl install JSON
해주면 되지만, gentoo에서는 뭔가 에러가 잔뜩 나온다. 이때,
USE="json exif" emerge dev-lang/php
명령어로 설치해주면 되더군.

<?php
$url = "http://udanax.org/shorturl.jsp?mode=api&longurl=".urlencode("http://lyrics.udanax.org/lyrics.php?title=%EB%84%88+%EC%95%84%EB%8B%88%EB%A9%B4+%EC%95%88%EB%8F%BC&id=672028");
echo $url;
$response = str_replace(");","", str_replace("null(","",file_get_contents($url)));
$json = json_decode($response, true);
echo $json['shorturl'];
?>

Plus, file_get_contents() 함수에서 에러나면,

Solution:
allow_url_fopen should be ON in PHP configuration (php.ini). Probably, you don’t have access to edit this file and it could also be that your hosting company has restricted changing the allow_url_fopen value. In this case, you should refer to them and ask them to set the value of allow_url_fopen to ON.

P.S. 프로그래밍 언어 중 내가 제일 싫어하는 것들: c, c++, php, shell script

No comments:

Post a Comment