<?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 美元的部分得到回应。我该怎么做?
你不需要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'];