Advertisement
Guest User

Untitled

a guest
Jan 25th, 2014
8
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.70 KB | None | 0 0
  1. <?php
  2.  
  3. function getPopularItems() {
  4.     $MARKET_URL = "http://steamcommunity.com/market/";
  5.     $DELIM_DROP = 'market_listing_table_showmore';
  6.     $PRICE_PATTERN = '@Starting at(?:.*)&#36;(.*)\</span\>@isU';
  7.     $ITEM_PATTERN = '@\<span id\="result_(?:.*)_name" class\="market_listing_item_name" style\="(?:.*);"\>(.*)\</span\>@isU';
  8.     $raw = "";
  9.     $handle = @fopen($MARKET_URL, "r");
  10.     if (!$handle) {
  11.         trigger_error("FOPEN - Connection Error. ");
  12.         return false;
  13.     } else {
  14.         while (!feof($handle)) {
  15.             $zeile = fgets($handle);
  16.             if (strpos($zeile, $DELIM_DROP)) {
  17.                 break;
  18.             }
  19.             $raw.=$zeile;
  20.         }
  21.         fclose($handle);
  22.     }
  23.     $result = preg_match_all($PRICE_PATTERN, $raw, $subpattern);
  24.     if (!$result) {
  25.         trigger_error("PRICE_PATTERN failure");
  26.         return false;
  27.     } else {
  28.         $prices = array_map("htmlentities", array_map("trim", $subpattern[1]));
  29.     }
  30.     $result = preg_match_all($ITEM_PATTERN, $raw, $subpattern);
  31.     if (!$result) {
  32.         trigger_error("ITEM_PATTERN failure");
  33.         return false;
  34.     } elseif (count($subpattern[1]) != count($prices)) {
  35.         trigger_error("ITEM_PATTERN and PRICE_PATTERN-Results does not match");
  36.         return false;
  37.     } else {
  38.         $names = array_map("htmlentities", array_map("trim", $subpattern[1]));
  39.     }
  40.     return array_map(null, $names, $prices);
  41. }
  42.  
  43. $Items = getPopularItems();
  44. if ($Items) {
  45.     foreach ($Items as $item) {
  46.         // Name
  47.         echo $item[0];
  48.        
  49.         echo " - ";
  50.        
  51.        
  52.         // Preis
  53.         echo $item[1];
  54.        
  55.        
  56.         echo "<br>";
  57.     }
  58. }
  59. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement