Just want to say Hi first of all, this is my first post and I am needing some help. Ive searched google and many other tutorials along with php.net and I cant seem to figure this out. I originally got help with this code from someone I can no longer get a hold of, and so im stuck now and need some help.
Anyways I have this code below that worked perfect about 3-4 weeks ago and now for some reason its not working. The code took values of stock prices from a website listed in the code and put those values into my website.
I have not changed anything with my code so I am guessing they may have changed something on their end. I would like to know what may be wrong with this code and if I am not searching the right fields or variables.
Please let me know if you have any ideas. Thanks.
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://www.bloomberg.com/markets/commodities/energyprices.html");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, 0);
$contents = curl_exec($ch);
curl_close($ch);
function find_values ($string, $page)
{
$string = preg_quote($string, '#');
// takes everything from the given string to end of row
preg_match("#$string(.*)</tr>#Us", $page, $match);
// Get the values from the row we found previously
preg_match_all("#<span[^>]*>([^<]*)</span>#s", $match[1], $values);
// Return the values
return $values[1];
}
$find1 = find_values('nymex crude future', $contents);
echo "Nymex Crude Future: Price = $find1[0], Change = $find1[1], & Change = $find1[2], Time = $find1[3]<br>";
$find2 = find_values('Dated Brent Spot', $contents);
echo "Nymex Heating Oil Future: Price = $find2[0], Change = $find2[1], & Change = $find2[2], Time = $find2[3]<br>";
$find3 = find_values('WTI Cushing Spot', $contents);
echo "Nymex RBOB Gasoline Future: Price = $find3[0], Change = $find3[1], & Change = $find3[2], Time = $find3[3]<br>";))>
?>