Re: looking for source to pull data (price of oil)

[email protected] ("O. Lavell")
Newsgroups php.general
Message-ID <[email protected]>
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.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.