2015-03-03 18 views
1
<?php 
$doc = new DOMDocument(); 
$doc->loadHTMLFile("http://steamcommunity.com/market/priceoverview/?country=US&currency=1&appid=570&market_hash_name=Goldhorn"); 
echo $doc->saveHTML(); 
?> 

它回聲Loadhtmlfile和回聲某一部分

{"success":true,"lowest_price":"$2.70","volume":"870","median_price":"$2.62"} 

我只希望在$ 2.70部分進行呼應。我將如何做到這一點?

回答

0

你並不需要爲這個HTML解析器(DOM文檔),它返回一個JSON字符串,使用json_decode()此:

$url = 'http://steamcommunity.com/market/priceoverview/?country=US&currency=1&appid=570&market_hash_name=Goldhorn'; 
$contents = json_decode(file_get_contents($url), true); 
echo $contents['lowest_price']; 
+0

謝謝,這個作品完美! – 2015-03-03 09:28:36

+0

@DanielAguilar確實很高興這樣流下了一些燈 – Ghost 2015-03-03 09:30:19