Jump to content

PHP stock Quotes


sunnysideup

Recommended Posts

Dear All,

 

I'm trying to parse yahoo quotes using their csv service, everything is runing well, but i cant get to load an image dynamically, my code (without image link) is as follows:

 

<?php

$quote = $_GET['company'];
$url = "http://in.finance.yahoo.com/d/quotes.csv?s=" . $quote . "&f=sl1d1t1c1ohgvwmj5j6k4k5t7m3m7m8m4m5m6npbaa5a2kj&e=.csv";

//open it for reading
$fp = fopen($url , "r");

//if no connection exists display error message
if (!fp) {
    echo "could not connect to the site";
}else {
    //store the csv file info in the array $data
    $data = fgetcsv($fp,1000,",");
    //close the file
    fclose($fp);
?>
  <table>
    <tr><td colspan="2">CHART IMAGE FROM http://ichart.finance.yahoo.com/b?s=GOOG</td></tr>
    <tr><td>Last Trade</td><td><?php echo $data[1] ?></td></tr>
    <tr><td>date</td><td><?php echo $data[2] ?></td></tr>
    <tr><td>time</td><td><?php echo $data[3] ?></td></tr>
    <tr><td>change</td><td><?php echo $data[4] ?></td></tr>
    <tr><td>open</td><td><?php echo $data[5] ?></td></tr>
    <tr><td>high</td><td><?php echo $data[6] ?></td></tr>
    <tr><td>low</td><td><?php echo $data[7] ?></td></tr>
    <tr><td>Volume</td><td><?php echo $data[8] ?></td></tr>
    <tr><td>52 Week Range</td><td><?php echo $data[9] ?></td></tr>
    <tr><td>Days Range</td><td><?php echo $data[10] ?></td></tr>
    <tr><td>Change From 52-wk Low</td><td><?php echo $data[11] ?></td></tr>
   <tr><td>% Chg From 52-wk Low</td><td><?php echo $data[12] ?></td></tr>
   <tr><td>Change From 52-wk High</td><td><?php echo $data[13] ?></td></tr>
   <tr><td>% Change From 52-wk High</td><td><?php echo $data[14] ?></td></tr>
   <tr><td>Ticker Trend</td><td><?php echo $data[15] ?></td></tr>
   <tr><td>50-day Moving Avg</td><td><?php echo $data[16] ?></td></tr>
   <tr><td>Change From 50-day Moving Avg</td><td><?php echo $data[17] ?></td></tr>
   <tr><td>Pct Chg From 50-day Moving Avg</td><td><?php echo $data[18] ?></td></tr>
   <tr><td>200-day Moving Avg</td><td><?php echo $data[19] ?></td></tr>
   <tr><td>Change From 200-day Moving Avg</td><td><?php echo $data[20] ?></td></tr>
   <tr><td>Pct Chg From 200-day Moving Avg</td><td><?php echo $data[21] ?></td></tr>
   <tr><td>eg..</td><td><?php echo $data[22] ?></td></tr>
   <tr><td>Previous Close</td><td><?php echo $data[23] ?></td></tr>
   <tr><td>Bid</td><td><?php echo $data[24] ?></td></tr>
   <tr><td>Ask</td><td><?php echo $data[25] ?></td></tr>
   <tr><td>Ask Size</td><td><?php echo $data[26] ?></td></tr>
   <tr><td>Average Daily Volume</td><td><?php echo $data[27] ?></td></tr>
   <tr><td>52week High</td><td><?php echo $data[28] ?></td></tr>
   <tr><td>52 Week Low</td><td><?php echo $data[29] ?></td></tr>
    </table>
<?php
}
?>

 

Now i want to include chart image from http://ichart.finance.yahoo.com/b?s=GOOG  ??? (Please see line 19 in the above code)

Wherin "GOOG" should be loaded from "$quote = $_GET['company']

 

Can anyone please help.

 

regards

Link to comment
Share on other sites

feel free to ignore redarrow.

 

since the output of that yahoo charts service is an image, you should be able to put it directly in the image's source attribute, like so:

 

<img src="http://ichart.finance.yahoo.com/b?s=<?php echo $_GET['company']; ?>" alt="<?php echo $_GET['company']; ?> Trading Chart" />

 

if the charts are always fixed dimensions, you should toss those into the image tag for good measure.

Link to comment
Share on other sites

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.