<?php
$doc = new DOMDocument();
$doc->loadHTMLFile("http://steamcommunity.com/market/priceoverview/?country=US¤cy=1&appid=570&market_hash_name=Goldhorn");
echo $doc->saveHTML();
?>
它回声
{"success":true,"lowest_price":"$2.70","volume":"870","median_price":"$2.62"}
我只希望2.70美元的部分得到回应。我该怎么做?
答案 0 :(得分:0)
为此,您不需要HTML解析器(DOMDocument),它会返回一个JSON字符串,为此使用json_decode()
:
$url = 'http://steamcommunity.com/market/priceoverview/?country=US¤cy=1&appid=570&market_hash_name=Goldhorn';
$contents = json_decode(file_get_contents($url), true);
echo $contents['lowest_price'];