Re: looking for source to pull data (price of oil)
| From: | O. Lavell | Date: | Tue, 16 Jun 2009 09:52:32 +0000 |
| Subject: | Re: looking for source to pull data (price of oil) | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-294069@lists.php.net to get a copy of this message | ||
Kurrent wrote:
> I am just simply looking for the price of nymex crude future ( see
> http://www.bloomberg.com/energy/).
>
> Any sources or other idea would be much appreciated. Thanks!
This seems to work:
<?php
ini_set("user_agent", "Mozilla/5.0");
$page = strip_tags(file_get_contents("http://www.bloomberg.com/energy/"));
$search = "Nymex Crude Future";
$start = strpos($page, $search) + strlen($search);
$price = floatval(substr($page, $start, 5));
echo($price);
?>
It assumes a. the Bloomberg page will stay the same, b. the Nymex price
will always be 5 characters and c. that this is for private use, because
Bloomberg is likely going to be very unhappy about you republishing their
data.
That said, I would personally have no qualms using this for a limited
scope intranet application for instance.