Switch to full style
Dynamic open source server-side web development
Post a reply

php code to get yahoo stock data

Tue Nov 03, 2009 7:53 pm

PHP code to get yahoo stock data

i have write a php code to get yahoo stock data , when i fetch the web data it saves the data as text file in to host server local drive (c:\ ), but i want to save the yahoo stock data from any remote pc from where i browse the page and it saves the data as text file automatically in local pc's c drive .
is there any way to do this , please help...........
here is the code

Code:
 
$quotes 
=array('DOW','SPX','GOLD','OIL','AIG','APPLE','AMGN','BAC','DISH',
'DO','DIRECTV','FEDEX','GOOG','HD','IBM','INTEL','IP','COLA','LOWES',
'YEN','EUR' ,'HK','JAP','AUS','INDIA');
//here you can out symbols of stock data
$args   = implode('&s=', $quotes);
//$file   = fopen("http://finance.yahoo.com/d/quotes.csv?s=$args&f=slp11d1t1c1ohgv&ej3j1x=.csv", "rb");
 $file   = fopen ("http://finance.yahoo.com/d/quotes.csv?s=$args&f=noc1&ex=.csv","r");
$data   = array();
$table  = '';

if ($file) {
  while($stocks = fgetcsv($file)) {
    $data[$stocks[0]] = $stocks;
  }
  fclose($file);
}

$table .= "<table border='1'>\n";
$table .= "<tr><th colspan='5'>".date('Y-m-d h:i:s A')."</th></tr>\n";
$table .= "<tr>\n";
foreach ($data as $sym => $info) {
  $table .= "\t<th>$sym</th>\n";
  foreach ($info as $item) {
    $table .= "\t<td>$item</td>\n";
  }
  $table .= (end($data) == $info) ? "</tr>\n" : "</tr>\n<tr>\n";
}
$table .= "</table><br/>";
echo $table;
//file_put_contents('stocks.html', $table, FILE_APPEND);
file_put_contents('C:\stocks.rtf', $table);
 




Re: php code to get yahoo stock data

Wed Dec 16, 2009 5:51 pm

Here is how you do it:
Code:
//echo $table;
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Type: html");
header("Content-Disposition: attachment;filename=mystock.html;");
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".strlen($table));
set_time_limit(0);
echo $table;

//file_put_contents('stocks.html', $table, FILE_APPEND);
//file_put_contents('C:\stocks.rtf', $table);


Post a reply
  Related Posts  to : php code to get yahoo stock data
 Arithmetic data comparison and decompression java code     -  
 Huffman Data compression-decompression code C#-csharp     -  
 LZW data compression-decompression algorithm java code     -  
 stock follow up     -  
 Learn Technical analysis and stock market tricks for free     -  
 i want code for connecting mobile and pc can u send me code     -  
 Freeman chain code algorithm code     -  
 c++/data structure     -  
 Data set for ID3 algorithm     -  
 What is Data integration?     -