How to Use PHP to Obtain Stock Quotes from Yahoo! Finance
The function will, by default, return the details of some of the stock markets:
The function will then use either an input list or the default list to create the correct url:
and then read in the data stream from the Yahoo! Finance web site:
The data will be in the format:
and so the next stage is to load the data into an array (using the new line as a delimiter):
finally the results can be output (taking care to remove the additional quotation marks):
Name | Stock Quote | Change"; foreach ($quote_array as $quote_value) { echo " |
---|---|---|
$symbol | $value | $change | ";
}
?>
Using the PHP Function to Display Yahoo! Finance Data to your
Once the function and library have been saved then they can be used in a PHP web page (for instance index.php) to display the default stock market data:
or used in a PHP file that can process the input from a textarea box:
If this code is stored in a file (for example yahoo_finance_lookup.php) then it can be called from a form:
No comments:
Post a Comment