PHP

AS3: Yahoo Stocks via PHP Proxy

01/02/2010 in RIA Comments

To follow a recent post about AS3 and Yahoo stocks using ColdFusion as a proxy below is some code to get the same information using PHP. I have been asked by several people on how to do this with PHP, which is not my typical scripting language. I decided to dig into it to see what the comparable method in PHP is to CFHTTP.FileContent. Turns out that the comparable function in PHP is “file_get_contents”.

<?php
//Get the file content and assign the string to $teststock
$teststock = file_get_contents('http://download.finance.yahoo.com/d/quotes.csv?s=^DJI&f=sl1d1t1c1ohgv&e=.csv');
 
//Split the string into an array to access each property of the stock
$teststring = split(",",$teststock);
 
//Print the new array to the screen
print_r($teststring);
 
print("<br /><br />");
 
//Print a specific point in the array, in this case the first one
print_r($teststring[0]);
 
print("<br /><br />");
 
//Print a specific point in the array, in this case the second one
print_r($teststring[1]);
 
?>