View Full Version : need help to get stock quote data in txt file

10-28-2009, 10:40 AM
hi im newbies in PHP, im writing a php script to get Real Time Yahoo Finance Stock Quotes data and works fine and fetch data to web page but i want to store these data in to a test file like putting log of those data so i wrote this c.v to create log text file file_put_contents("sq3.txt", "$myFile ", FILE_APPEND); and it create a sq3.txt file but but here i did not get data , it shows like :
Array Array Array Array Array Array Array Array Array Resource id #3 Resource id #6 Resource id #9 Resource id #12 Resource id #15 Resource id #18 Resource id #21 Resource id #24 Resource id #27

here is the full code :
$quotes[] = "msft";
$quotes[] = "amzn";
$quotes[] = "macr";
$quotes[] = "rhat";
$quotes[] = "orcl";
$quotes[] = "yhoo";
$quotes[] = "penn";
$quotes[] = "ibm";
$quotes[] = "goog";

$indexLimit = count($quotes);

for($index=0; $index<$indexLimit; $index++) {
$quote = $quotes[$index];
$file = "http://finance.yahoo.com/d/quotes.csv?s=$quote&f=sl1d1t1c1ohgv&e=.csv";
if($myFile = fopen("$file","r"))
while (!feof ($myFile)) {
$myField = fgetcsv($myFile,1024);
for($n=0; $n<count($myField); $n++) {
if($n == "0"){
} else {
file_put_contents("sq3.txt", "$myFile ", FILE_APPEND).PHP_EOL;

please any one help me to solve this with log file overwriting features

10-28-2009, 04:39 PM
The variable $myFile is just a pointer to what PHP calls a resource, which is, in your case, an opened file. The actual data in the file is retrieved and put into a variable when you call that fgetcsv() function. The data goes into the $myField variable as an array. This array is what you need to write to your log file.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum