• Log in or sign up for an account here: https://www.sythe.org/login

Help: GE Price Grabber

Jon_d2

Newcomer
Joined
Feb 20, 2009
Sythe Gold
0
Messages
14
Location
North Wales, UK
Ok, So i'm developing a script in PHP that will grab the price from the Runescape website of items on the grand exchange. I have completed the HTML grabbing, now all i need to do is scan though the HTML and take out the price. I have a good idea about how to go about doing this, by using regular expressions. But I can't seem to find a way to take out what's infront of "market price:", "maximum price:", and "minimum price:". Here is my script so far:

<?php

$ch = curl_init();
$id = "9004";
curl_setopt($ch, CURLOPT_URL, "http://itemdb-rs.runescape.com/viewitem.ws?obj=".$id);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
curl_close($ch);

$string = $output;

if(preg_match("/market price:/i", $string))
{
echo 'Matched Found';
}else{
echo 'No match found';
}


?>

As you can see, I don't have a way to take out the value that comes after the market price.

I have been searching for an answer for about an hour now, and I really need some help. Any help would be greatly appreciated.

Thanks, Jon_d2.
 
You can use regular expressions, but you don't need to - there is a simpler way.

Look into the split() function.

Let's say the source of our page was this:
Code:
<table>
<tr><td>Market Price</td><td>9999 GP</td></tr>
<tr><td>Other Price</td><td>2192 GP</td></tr>
</table>

If we wanted the Market Price, we would do something similar to this:
PHP:
<?PHP
// Let's assume that $page contains our data

// Following line leaves $marketPrice with an array of everything
// BEFORE AND AFTER the first argument in the split() function.
$marketPrice = split("<tr><td>Market Price</td><td>", $page);

// Following line leaves  us with everything AFTER the first 
// argument as seen in the previous part
$marketPrice = $marketPrice[1];

// Now we have everything after the part we split it by. 
// Now we want to isolate the price.
$marketPrice = split(" GP</td></tr>", $marketPrice);
$marketPrice = $marketPrice[0];

echo $marketPrice; // You will see "9999" as output. 
?>
 
Runescape Gamblingrunescape gambling
Back
Top