Jump to content

How to get the GE price of an item using PHP?


nightshade53

Recommended Posts

Well, the first thing that comes to mind is to cURL them and use simpleXML, but I seem to remember that the URLs change or something, making that difficult... Also there is no light version of the GE.

C2b6gs7.png

Link to comment
Share on other sites

It's fairly easy, you just need to know the ID of the item you want to grab...

 

 

 

      

	// Enter your item ID here.

	$itemid = 10392;



	$curl = curl_init();

	curl_setopt($curl, CURLOPT_URL, "http://itemdb-rs.runescape.com/viewitem.ws?obj=".$itemid);

	curl_setopt($curl, CURLOPT_BINARYTRANSFER, 1);

	curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);

	curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 3);

	curl_setopt($curl, CURLOPT_TIMEOUT, 6);

	$fullge =  curl_exec($curl);

	$curl_http = curl_getinfo($curl, CURLINFO_HTTP_CODE);

	curl_close($curl);



	if ($curl_http == "404") {



		// For some reason Jagex has deleted the GE :D

		// Do whatever you need to here.

	}



	if (strpos($fullge, "The item you were trying to view could not be found.") !== FALSE) {



		// The item doesn't exist.

		// Do whatever you need to here.

	}



	ereg('Minimum price: ([0-9\.km,]+)', $fullge, $regex['minprice']);

	ereg('Market price: ([0-9\.km,]+)', $fullge, $regex['markprice']);

	ereg('Maximum price: ([0-9\.km,]+)', $fullge, $regex['maxprice']);



	/*

	 * Element [1] of the $regex arrays now contains the prices from the GE.

	 * Running them through trim() first is a good idea just to be safe.

	 *

	 */



	 // Just to prove it works!

	 print_r($regex);

 

 

 

Obviously that can very easily be turned into a function to grab the data for a given item ID.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.