2013-04-28 2 views
0

URL이 http://btcrate.com/convert?from=btc&to=usd&exch=mtgox&conv=xe&amount=0.01{"converted": "1.300000300"}입니다. PHP 값으로 변환 된 값을 얻고 싶습니다. 따라서 $usd = 1.300000300;.URL에서 배열 값 가져 오기


나는 다음을 시도했지만 단지 변환 된 값을 원하지만 전체 문자열 만 출력합니다. 배열을 사용하는 당신은 JSON을 디코딩 한 후 간단하게 converted

$data = file_get_contents("http://btcrate.com/convert?from=btc&to=usd&exch=mtgox&conv=xe&amount=0.01"); 

$obj = json_decode($data); 
$converted = $obj->{'converted'}; 

echo $converted; 

Learn more about using JSON in PHP here

답변

2

JSON 형식으로되어 있습니다 :

$string = file_get_contents("http://btcrate.com/convert?from=btc&to=usd&exch=mtgox&conv=xe&amount=0.01"); 

$result = json_decode($string, true); 
$converted = $result['converted']; 

echo $converted; 
0

또 다른 가능성의 값을 검색 할 수 있도록 데이터가 반환되는

file_get_contents("http://btcrate.com/convert?from=btc&to=usd&exch=mtgox&conv=xe&amount=0.01");