"Chris Mosser" <cmosser_at_com cast_dot_net> wrote:
I'm looking to add a page to my site where I can get stock quotes for the
wired, but more importantly, the wireless web(ie my cell phone). I know
how write the needed php and WAP application, I just don't know where to
get the stock market feed, at least not without parsing a
finance.yahoo.c om page.
Or something else like it that could change at any time. I'm looking for
just the raw data feed. Anyone ever had to do this and can give me some
info on a feed??????
--
Chris Mosser
Hi
I just wrote a bunch of them. :P
You CAN use Yahoo without parsing the HTML.
Use their
http://quote.yahoo.com/download/quotes.csv
Here follows a clumsy script to get you going:
(sorry, I think I exceed linelength, you have to repair by hand)
Regards,
Erwin Moller
function getAllQuotes($s ymbolsarray) {
// returns an array with arrays with data
$allQuotes = array();
$baseurl =
"http://quote.yahoo.com/download/quotes.csv?form at=snlx&ext=.cs v&symbols=";
// make the symbols urlencoded.
$urlsymbols = urlencode(implo de(" ",$symbolsarray ));
$quotesURL = $baseurl.$urlsy mbols;
$csv = file($quotesURL );
foreach ($csv as $line_num => $line) {
// if NOT exists format: "^AEX2","^AEX2" , "N/A - <b>0.00</b>",
"N/A"
// if exists format: "^AEX" ,"AEX-Index","7:37
am - <b>326.71</b>", "Amsterdam"
//
"AHOc.BA","ROYA L AHOLD","Aug 28, 2002 - <b>16.435</b>","Buenos Aires"
//
"MSFT.AS","MICR OSOFT CORP","Oct 20 - <b>27.82</b>","Amsterdam "
// Please not the , in the date of AHOc.BA
// shame I don't know a better value for the 'format' in the baseurl.
:-(
// split on ","
$parts = explode("\",\"" ,$line);
$oneQuote = array();
$oneQuote["symbol"] = trim(trim($part s[0]) , "\"");
$oneQuote["name"] = trim(trim($part s[1]) , "\"");
$oneQuote["place"] = trim(trim($part s[3]) , "\"");
$val = trim($parts[2] , "\"");
// remove all before <b> and remove the last </b>
// remove 6:30am - <b>
$val = substr($val, strpos($val, "<b>")+3) ;
// remove </b>
$val = substr($val , 0 , -4) ;
$oneQuote["value"] = $val;
// add to allQuotes
$allQuotes[$oneQuote["symbol"]] = $oneQuote;
}
return $allQuotes;
}