Anybody know if there's a way to pull gas prices from any of those gas price websites, so I can display them on my own page? I didn't know if there's a way to tap in to their source or if they provide some sort of way to do that. Reason is I'm writing a little app and I would like to have the gas prices of a couple local stations used in some calculations in my app. An example of one of those sites would be www.gasbuddy.com.

Oh, FYI, the reason I posted this in the PHP forum is that I will be using PHP to write the app.

9 Years
Discussion Span
Last Post by ha1e

Hm, good info. I'll take a look into it and let you know how it goes. This just might work. Thanks!


It is possible to use fopen() in PHP5 to send a POST request and obtain the content in a variable, check this tutorial:

According to the amount of data, sometimes is more fast and useful to use only string functions, with a combination of strpos() and substr(); other method is using regular expressions.

With larger files or complex patterns is recommended to use SimpleXML functions (PHP5), like is described in the first tutorial suggested by Ezzaral. Xpath would be a good improvement to locate elements easily.

Some sites have clean XML results and search API easily obtainable by public, with some limitations, like the Kayak API to search flights in tourism sites. Really, I don’t know if there is a such solution for your industry, some sites contain manuals and examples to implement search and get results on their sites.

Votes + Comments
good info

Thanks for that reply. I will be simply pulling one number every time the script is run. A specific gas price. I'll look into your ideas as well.


This code gets the today's gas price
It's easy to get it on this site because the price is placed between a span with the id "GBPS_lblUSToday"

$arr = file("http://www.gasbuddy.com/");

$gasprice = "";
foreach ($arr as $key => $line)
    if (strstr($line, "GBPS_lblUSToday"))

echo strip_tags($gasprice);

If you need any help,don't hesitate to ask me :P


Eko I like your code, but can anyone tell me how you would do this for pulling from multiple lines with the same span id?

Many Thanks


This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.