解析来自远程服务器的JSON数据
问题描述:
我想知道是否有任何方法可以在PHP中使用解析器从该网站获取值 https://btc-e.com/api/2/btc_usd/ticker
并将其设置为php代码中的变量?
I was wondering if there was any way to make a Parser in PHP in which gets the values from this site https://btc-e.com/api/2/btc_usd/ticker
and sets them as variables in php code?
我稍微看过php解析器,发现的唯一一件事就是解析器,该解析器回显了网站上的所有信息.
I have looked at php parsers a bit and the only thing I found was parsers that echo all the information on a website.
答
由于该URL返回了JSON
响应:
Since that URL returns a JSON
response:
<?php
$content=file_get_contents("https://btc-e.com/api/2/btc_usd/ticker");
$data=json_decode($content);
//do whatever with $data now
?>