Yahoo Stock Ticker

I found the following PHP code that brings back a stock quote fro Yahoo.

<?php
$arr = array('IBM');
$url= "http://finance.yahoo.com/d/quotes.csv?s=".implode("+", $arr)."&f="."snl1c1jkd1t1";
echo "<table><tr><td>Symbol</td><td>Name</td><td>Last Trade</td><td>Change</td><td>52 Week Low</td><td>52 Week High</td><td>Last Trade Date</td><td>Last Trade Time</td></tr>";
$handle = fopen($url, "r");
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE)
{
echo "<tr>";
foreach($data as $d)
echo "<td>$d</td>";
echo "</tr>";
}
fclose($handle);
echo "</table>";
?>

Open in new window

It returns 6 things but I only want one: Last Trade the third part of the argument. Not sure how to that.
LVL 8
rgranlundAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ray PaseurCommented:
Please see: http://iconoun.com/demo/temp_rgranlund.php
<?php
/**
 * http://www.experts-exchange.com/questions/28814599/Yahoo-Stock-Ticker.html
 */
error_reporting(E_ALL);
echo '<pre>';

$arr = array('IBM');
$url= "http://finance.yahoo.com/d/quotes.csv?s=".implode("+", $arr)."&f="."snl1c1jkd1t1";

// ACTIVATE THIS TO SEE THE URL
// var_dump($url);

$handle = fopen($url, "r");
$data = fgetcsv($handle, 1000, ",");

// ACTIVATE THIS TO SEE THE CSV-INTERPRETED DATA
// var_dump($data);


// GET THE SYMBOL AND THE LAST PRICE
$sym = $data[0];
$bux = $data[2];
echo PHP_EOL . "Symbol: <b>$sym</b>, Last Trade Price: $bux";

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ray PaseurCommented:
I believe you can also modify that URL string to something less than snl1c1jkd1t1 and thereby get a more concise response.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.