nitrus Posted March 9, 2013 Share Posted March 9, 2013 (edited) <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 March 9, 2013 by nitrus Quote Link to comment https://forums.phpfreaks.com/topic/275429-not-all-stock-information-is-showing-up-please-help/ Share on other sites More sharing options...
Barand Posted March 9, 2013 Share Posted March 9, 2013 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> Quote Link to comment https://forums.phpfreaks.com/topic/275429-not-all-stock-information-is-showing-up-please-help/#findComment-1417714 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.