nutt318 Posted December 15, 2007 Share Posted December 15, 2007 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>")> ?> Quote Link to comment Share on other sites More sharing options...
phpQuestioner Posted December 15, 2007 Share Posted December 15, 2007 PHP Screen Scraping Techniques http://www.google.com/search?hl=en&sa=X&oi=spell&resnum=0&ct=result&cd=1&q=PHP+Screen+Scraping&spell=1 Quote Link to comment Share on other sites More sharing options...
nutt318 Posted December 16, 2007 Author Share Posted December 16, 2007 I have tried searching many places but nothing is making sense. Does anyone know what is wrong with my code? Quote Link to comment Share on other sites More sharing options...
nutt318 Posted December 17, 2007 Author Share Posted December 17, 2007 Can anyone else tell me what is wrong with my code? Or does anyone have any other way of doing this? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.