Jump to content

Getting data feild from another source


nutt318

Recommended Posts

I wanted to know if there is a way that I can get a value from a table on another site and transfer that info to my site. Basically the site I want to get info from is a website that has stock prices, and I would like to get a certian field from that site to put on my site.

 

So basically you can go to my page and it will pull these vales from the other site. I have an example that did work at one time but now for some reason it is no longer working. I am not sure why its not working but if there is another way to do the same thing it would be helpful.

 


<?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>")>


?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.