PHP applications that involve accessing stock symbol prices, changes, and additional details on a repeated basis can be easily obtained from Yahoo. The below url will open an excel spreadsheet. Simply replace XXX with a comma delimited list of stock ticker symbols.
http://finance.yahoo.com/d/quotes.csv?s=XXX&f=sl1d1t1c1ohgv&e=.csv
The resulting spreadsheet displays a row for each ticker with the following informations from columns A to I: symbol, last price, date, time, change, open, high, low, and volume. To incorporate the above url into PHP, follow the below script that handles one ticker. We will use Google (GOOG) as an example. The script will output the result from the spreadsheet into an html table.
<?php
$fp = fopen (”http://finance.yahoo.com/d/quotes.csv?s=goog&f=sl1d1t1c1ohgv&e=.csv”,”r”);
$data = fgetcsv ($fp, 1000, “,”)
?>
<table>
<tr><td>description</td><td>latest figure</td><tr>
<tr><td>symbol</td><td><?php echo $data[0] ?></td></tr>
<tr><td>last price</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>
</table>
<?php
fclose ($fp);
?>
In the above script example, the fopen function opens the file to be read. Next, the fgetscv function moves cells from a CSV excel file into an array. The array can then be manipulated as necessary. Lastly, the fclose function closes the the open file.
Altering this code to handle multiple stock ticker symbols in one sheet would be possible, but would make this simple example a bit more complex. This script will however get you started with getting the stock information you need for your PHP web application.