Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Oct 2009
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    need help to get stock quote data in txt file

    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);

    print("<table>");
    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)) {
    print("<tr>\n");
    $myField = fgetcsv($myFile,1024);
    for($n=0; $n<count($myField); $n++) {
    print("<td>");
    if($n == "0"){
    print("<b>$myField[$n]</b>");
    } else {
    print("$myField[$n]");
    }
    print("</td>\n");
    }
    print("</tr>\n");
    }
    fclose($myFile);
    }
    file_put_contents("sq3.txt", "$myFile ", FILE_APPEND).PHP_EOL;
    }
    print("</table>");
    ?>

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

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    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.


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •