Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function getPopularItems() {
- $MARKET_URL = "http://steamcommunity.com/market/";
- $DELIM_DROP = 'market_listing_table_showmore';
- $PRICE_PATTERN = '@Starting at(?:.*)$(.*)\</span\>@isU';
- $ITEM_PATTERN = '@\<span id\="result_(?:.*)_name" class\="market_listing_item_name" style\="(?:.*);"\>(.*)\</span\>@isU';
- $raw = "";
- $handle = @fopen($MARKET_URL, "r");
- if (!$handle) {
- trigger_error("FOPEN - Connection Error. ");
- return false;
- } else {
- while (!feof($handle)) {
- $zeile = fgets($handle);
- if (strpos($zeile, $DELIM_DROP)) {
- break;
- }
- $raw.=$zeile;
- }
- fclose($handle);
- }
- $result = preg_match_all($PRICE_PATTERN, $raw, $subpattern);
- if (!$result) {
- trigger_error("PRICE_PATTERN failure");
- return false;
- } else {
- $prices = array_map("htmlentities", array_map("trim", $subpattern[1]));
- }
- $result = preg_match_all($ITEM_PATTERN, $raw, $subpattern);
- if (!$result) {
- trigger_error("ITEM_PATTERN failure");
- return false;
- } elseif (count($subpattern[1]) != count($prices)) {
- trigger_error("ITEM_PATTERN and PRICE_PATTERN-Results does not match");
- return false;
- } else {
- $names = array_map("htmlentities", array_map("trim", $subpattern[1]));
- }
- return array_map(null, $names, $prices);
- }
- $Items = getPopularItems();
- if ($Items) {
- foreach ($Items as $item) {
- // Name
- echo $item[0];
- echo " - ";
- // Preis
- echo $item[1];
- echo "<br>";
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement