-1

複数の $objectId のデータを収集するためにこれをループする方法は? $objectId 1038 から 1048 までのように。

以下に、データを収集できる完全なスクリプトを示します。ライン $objectId = ""; //I want to gather info about IDs lets say from 1038 - 1048内にあると思うループですが、うまくいきませんでした。

<form name="myForm" action="" method="post" id="myForm">
  <table cellpadding="2" border="1">
    <tr>
      <td width="264" rowspan="2" valign="top"><?php 

    function transformHTML($string)
    {
        $string = trim($string);
        $string = utf8_decode($string);
        $string = htmlentities($string, ENT_NOQUOTES);
        $string = str_replace("#", "&#35;", $string);
        $string = str_replace("%", "&#37;", $string);

        return $string;
    }

    function get_string_between($string, $start, $end){
        $string = " ".$string;
        $ini = strpos($string,$start);
        if ($ini == 0) return "";
        $ini += strlen($start);
        $len = strpos($string,$end,$ini) - $ini;
        return substr($string,$ini,$len);
    }

    if($_POST['submit']) { 

        $objectId = ""; //I want to gather info about IDs lets say from 1038 - 1048

            $error_B = "<span class=error>Error #2:<br> Does the item exist (ID: " . $objectId . ")?</span><br>";

            $lines = file('http://services.runescape.com/m=itemdb_rs/viewitem.ws?obj=' . $objectId);
            foreach ($lines as $line_num => $line) {
                $lineCrawl = htmlspecialchars($line);
                $StringSum = "$StringSum$lineCrawl";
            }
            $parsedGuidePrice = get_string_between($StringSum, "Current guide price", "Today");
            $parsedItemName = get_string_between($StringSum, "&lt;title&gt;", " - Grand Exchange - RuneScape&lt;/title&gt;");
            $parsedItemIconUrl  = get_string_between($StringSum, '&lt;meta property=&quot;og:image&quot; content=&quot;', '&quot; /&gt;');

            $guideprice = preg_replace("/[^\.kbm0-9]/", "", $parsedGuidePrice);

            if (strpos($guideprice,'k') !== false) {
                $guideprice = preg_replace("/[^0-9]/", "", $parsedGuidePrice);
                $guideprice *= 100;
            } else if (strpos($guideprice,'m') !== false) {
                $guideprice = preg_replace("/[^0-9]/", "", $parsedGuidePrice);
                $guideprice *= 100000;
            } else if (strpos($guideprice,'b') !== false) {
                $guideprice = preg_replace("/[^0-9]/", "", $parsedGuidePrice);
                $guideprice *= 100000000;
            } 
            if ($guideprice == "") { 
                echo $error_B; 
            } else { 
                echo "<img src='" . $parsedItemIconUrl . "' class='parsedItemIconUrl'>";
                echo "<br>";
                echo "<strong>" . $parsedItemName . "</strong> guide price: <strong>" . $guideprice . "</strong>"; 
                echo "<br>";
                echo "<small>(Item ID: " . $objectId . ")</small><br><br><br>";
            }
    }
    ?></td>
      <td width="172"></td>
      <td width="99"><input type="submit" name="submit" alt="Get yesterday's averge market price" title="Get yesterday's averge market price"></td>
    </tr>
    <tr valign="top">
      <td></td>
      <td><input value="Reset" type="button" name="reset" alt="Reset the form" title="Reset the form" onClick="javascript:window.location = '';"></td>
    </tr>
  </table>
</form>
4

1 に答える 1

1
<form name="myForm" action="" method="post" id="myForm">
  <table cellpadding="2" border="1">
    <tr>
      <td width="264" rowspan="2" valign="top"><?php 

    function transformHTML($string)
    {
        $string = trim($string);
        $string = utf8_decode($string);
        $string = htmlentities($string, ENT_NOQUOTES);
        $string = str_replace("#", "&#35;", $string);
        $string = str_replace("%", "&#37;", $string);

        return $string;
    }

    function get_string_between($string, $start, $end){
        $string = " ".$string;
        $ini = strpos($string,$start);
        if ($ini == 0) return "";
        $ini += strlen($start);
        $len = strpos($string,$end,$ini) - $ini;
        return substr($string,$ini,$len);
    }

    function echoObjectIdStuff($objectId) {
        $error_B = "<span class=error>Error #2:<br> Does the item exist (ID: " . $objectId . ")?</span><br>";

        $lines = file('http://services.runescape.com/m=itemdb_rs/viewitem.ws?obj=' . $objectId);
        foreach ($lines as $line_num => $line) {
            $lineCrawl = htmlspecialchars($line);
            $StringSum = "$StringSum$lineCrawl";
        }
        $parsedGuidePrice = get_string_between($StringSum, "Current guide price", "Today");
        $parsedItemName = get_string_between($StringSum, "&lt;title&gt;", " - Grand Exchange - RuneScape&lt;/title&gt;");
        $parsedItemIconUrl  = get_string_between($StringSum, '&lt;meta property=&quot;og:image&quot; content=&quot;', '&quot; /&gt;');

        $guideprice = preg_replace("/[^\.kbm0-9]/", "", $parsedGuidePrice);

        if (strpos($guideprice,'k') !== false) {
            $guideprice = preg_replace("/[^0-9]/", "", $parsedGuidePrice);
            $guideprice *= 100;
        } else if (strpos($guideprice,'m') !== false) {
            $guideprice = preg_replace("/[^0-9]/", "", $parsedGuidePrice);
            $guideprice *= 100000;
        } else if (strpos($guideprice,'b') !== false) {
            $guideprice = preg_replace("/[^0-9]/", "", $parsedGuidePrice);
            $guideprice *= 100000000;
        } 
        if ($guideprice == "") { 
            echo $error_B; 
        } else { 
            echo "<img src='" . $parsedItemIconUrl . "' class='parsedItemIconUrl'>";
            echo "<br>";
            echo "<strong>" . $parsedItemName . "</strong> guide price: <strong>" . $guideprice . "</strong>"; 
            echo "<br>";
            echo "<small>(Item ID: " . $objectId . ")</small><br><br><br>";
        }
    }

    if($_POST['submit']) { 
        for($id = 1038;  $id <= 1048; $id++) {
            echoObjectIdStuff($id);
        }
    }

    ?></td>
      <td width="172"></td>
      <td width="99"><input type="submit" name="submit" alt="Get yesterday's averge market price" title="Get yesterday's averge market price"></td>
    </tr>
    <tr valign="top">
      <td></td>
      <td><input value="Reset" type="button" name="reset" alt="Reset the form" title="Reset the form" onClick="javascript:window.location = '';"></td>
    </tr>
  </table>
</form>
于 2012-05-02T14:45:39.720 に答える