Jump to content

Recommended Posts

    <html>
    <body>
    <h2>Stock </h2>
    <?php
    
    //$ticker = "goog";
 
    
    if (isset($_GET['get_quote'])) {
    $ticker = $_GET['ticker'];
    }
    
    $open = fopen("http://download.finance.yahoo.com/d/quotes.csv?s=$ticker&f=sl1d1t1c1ohgv&e=.csv", "r");
    
    $quote = fread($open, 1000);
    
    fclose($open);
    
    $quote = str_replace("\"", "", $quote);
    $quote = explode(",", $quote);
    
    $stock_0 = ($quote[0]);
    $stock_1 = ($quote[1]);
    $stock_2 = ($quote[2]);
    $stock_3 = ($quote[3]);
    $sotck_4 = ($quote[4]);
    $stock_5 = ($quote[5]);
    
    
    echo "Company:      <b>$stock_0</b><br>";
    echo "Last trade:   <b>$stock_1</b><br>";
    echo "Date:         <b>$stock_2</b><br>";
    echo "Time:         <b>$stock_3</b><br>";
    echo "High:         <b>$sotck_4</b><br>";
    echo "Low:          <b>$stock_5</b><br>";
    
    ?>
    
    <br><br>
    <form action="stockfetch.php" method="get">
    
    Enter Quote: <input type="text" size="10" maxlength="10" name="ticker"/>
    <input type="submit" value="Enter Quote" name="get_quote" />
    </form>
    </body>
    </html>
 

 

 

 

Can you help me resolve the fix the "Undefined offset on line 1-5" i can't seem to figure out how to fix that error?

 

When i enter in symbol such as goog it retrieves the right stock information from the csv, but when i first load my stock fetcher it has problems?

 

When i type in other symbols it seems to yooh it comes with n/a but google seems to work.

Edited by nitrus

easier with fgetcsv()

 

Only open file if the there is GET data

 

GOOG and YHOO work OK

 

<?php

#$ticker = "goog"; 

    
if (isset($_GET['get_quote'])) {
    $ticker = $_GET['ticker'];
    $open = fopen("http://download.finance.yahoo.com/d/quotes.csv?s=$ticker&f=sl1d1t1c1ohgv&e=.csv", "r");
    $quote = fgetcsv($open, 1024);
        
    echo "Company:          <b>{$quote[0]}</b><br>";
    echo "Last trade:   <b>{$quote[1]}</b><br>";
    echo "Date:         <b>{$quote[2]}</b><br>";
    echo "Time:         <b>{$quote[3]}</b><br>";
    echo "High:         <b>{$quote[4]}</b><br>";
    echo "Low:          <b>{$quote[5]}</b><br>";
}
?>
   
  <br><br>
    <form action="" method="get">
    
    Enter Quote: <input type="text" size="10" maxlength="10" name="ticker"/>
    <input type="submit" value="Enter Quote" name="get_quote" />
    </form>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.