Searching the stock market
Want to get the latest stock quotes for your favorite stock symbol? This recipe will let us use the "stock" keyword to trigger a lookup of the latest stock quotes.
So for example, sending a text of "stock AAPL" will return the latest stock information for the AAPL symbol.
Getting ready
The complete source code for this recipe can be found in the Chapter5/
folder.
How to do it...
This recipe will let us search Yahoo Finance for today's price quote by using the stock symbol. Create a file called stock.php
in the pages
folder and add the following code to it:
<?php $results = stock( $keywords ); $i = 1; $reply = array(); $quote = $results->quote; $msg = $quote->symbol.' - '.$quote->LastTradePriceOnly.' - '.$quote->Change.' - '.$quote->PercentChange; $reply[] = $msg; print_sms_reply( $reply ); function stock( $symbol ){ $yelpql = " USE 'http://www.datatables.org/yahoo/finance/yahoo.finance.quotes.xml' AS yahoo.finance.quotes;select...