Get the price of an item on Steam Community Market with PHP and Regex -


i'm trying use php steam community market price of item. take url (for example : http://steamcommunity.com/market/listings/730/stattrak%e2%84%a2%20p250%20%7c%20steel%20disruption%20%28factory%20new%29) , download content file_get_contents(). tried use :

function getinnerhtml($string, $tagname, $closetagname) {     $pattern = "/<$tagname ?.*>(.*)<\/$closetagname>/";     preg_match($pattern, $string, $matches);     return $matches[1]; } 

using

getinnerhtml($str, 'span class="market_listing_price market_listing_price_with_fee"', 'span'); 

an example of can have file_get_contents :

<span class="market_table_value">     <span class="market_listing_price market_listing_price_with_fee">         $1.92               </span>     <span class="market_listing_price market_listing_price_without_fee">         $1.68               </span>     <br/> </span> 

but returns nothing.

has idea ?

not entirely sure why you'd want hard way , regex through html when there's working call returns json. although original answer correct , answers op question directly, provides easier , efficient way of getting market value of item.

get:

http://steamcommunity.com/market/priceoverview/?currency=3&appid=730&market_hash_name=stattrak%e2%84%a2%20p250%20%7c%20steel%20disruption%20%28factory%20new%29

json response:

{   "success": true,   "lowest_price": "1,43&#8364; ",   "volume": "562",   "median_price": "1,60&#8364; " } 

response definitions :

success: boolean value, true if call successful or false if went wrong or there no listing item on steam market.

lowest_price: string value currency symbol [pre-/ap]pended depending on query parameters specified. see below additional parameter.

volume: integer value returned string (?) - total number of specific item has been sold/bought.

median_price: string value currency symbol [pre-/ap]pended. average price @ item has been sold. see steam marketplace item graph better understanding on how median calculated.

query parameters:

appid: unique (statically defined) steam application id of game/app, in our case 730 counter-strike: global offensive. see valve's development wiki list of other appid's, though list out of date new apps added platform frequently.

market_hash_name: name of item being queried against exterior included, retrieving these names can found when querying against users inventory, that's whole other api call.

currency: integer value; currency value , format return market values. you'll need tweak , play around these numbers cannot provide detail here. stick using usd global price , use own currency api translate other currencies.


Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -