PX : code

Quick Quote by Eric Pfleckl
Download this code


<html>
<head>
    <title>Quick Quote</title>
    <meta http-equiv=\"Refresh\" content=\"300\">
    <meta http-equiv=\"EXPIRES\" content=\"0\">
    <meta http-equiv=\"Pragma\" content=\"no-cache\">
    <meta name=\"author\" content=\"Eric F. Pfleckl\">
    <style>
        h2 {font-size: 12pt; font-weight: bold; font-style: normal; font-family: 
Verdana, Arial, Helvetica, sans-serif}
        td {font-size: 8pt; font-weight: normal; font-style: normal; font-family: 
Verdana, Arial, Helvetica, sans-serif}
        p {font-size: 10pt; font-weight: normal; font-style: normal; font-family: 
Verdana, Arial, Helvetica, sans-serif}
        input {font-size: 8pt; font-family: Verdana, \'sans-serif\'}
    </style>
</head>
<body bgcolor=\"#ffffff\">
<h2>Quick Quote</h2>

<form>
    <p>Enter Up to 5 Stock Symbols:
    <input type=\"text\" name=\"symbol[0]\" size=\"5\" value=\"<? echo $symbol[0]; 
?>\" maxlength=\"5\">
    <input type=\"text\" name=\"symbol[1]\" size=\"5\" value=\"<? echo $symbol[1]; 
?>\" maxlength=\"5\">
    <input type=\"text\" name=\"symbol[2]\" size=\"5\" value=\"<? echo $symbol[2]; 
?>\" maxlength=\"5\">
    <input type=\"text\" name=\"symbol[3]\" size=\"5\" value=\"<? echo $symbol[3]; 
?>\" maxlength=\"5\">
    <input type=\"text\" name=\"symbol[4]\" size=\"5\" value=\"<? echo $symbol[4]; 
?>\" maxlength=\"5\">
    <input type=\"submit\" name=\"submit\" value=\"Go\">
</form>

<hr width=\"100%\">

<?

// If Yahoo changes their HTML results, the program will break here:

function cleanUpText($text, $stockSymbol){
    $text = str_replace(\'<td nowrap align=left><a 
href=\"/q?s=\'.strtoupper($stockSymbol).\'&d=t\">\'.strtoupper($stockSymbol).\"
</a>\", strtoupper($stockSymbol), $text);
    $text = str_replace(\'<td nowrap align=center><small><a 
href=\"/q?s=\'.$stockSymbol.\'&d=b\">Chart</a>, <a 
href=http://biz.yahoo.com/n/\'.substr($stockSymbol,0,1).\'/\'.$stockSymbol.\'.ht
ml>News</a>, \', \"\", $text);
    $text = str_replace(\'<a 
href=\"http://messages.yahoo.com/?action=q&board=\'.strtoupper($stockSy
mbol).\'\">Msgs</a>, \', \"\", \"$text\");
    $text = str_replace(\'<a 
href=http://biz.yahoo.com/p/\'.substr($stockSymbol,0,1).\'/\'.$stockSymbol.\'.ht
ml>Profile</a><br><a 
href=\"http://biz.yahoo.com/z/a/\'.substr($stockSymbol,0,1).\'/\'.$stockSymbol.\'.
html\">Research</a>, \', \"\", $text);
    $text = str_replace(\'<a 
href=\"http://biz.yahoo.com/t/\'.substr($stockSymbol,0,1).\'/\'.$stockSymbol.\'.ht
ml\">Insider</a>, <a 
href=\"/q?s=\'.$stockSymbol.\'&d=o\">Options</a></small></td>\', \"\", $text);
    $text = str_replace(\'<td  align=center><a 
href=\"http://finance.yahoo.com/ef?.done=http://finance.yahoo.com/q%3fs%
3d\'.strtoupper($stockSymbol).\'%26d%3dv1\"><small>Choose&nbsp;Brok
erage</small></a></td>\', \"\", $text);
    $text = str_replace(\" align=center\", \"\", $text);
    
    return $text;
}

function getQuote($symbol) {
    $targetURL = 
\'http://finance.yahoo.com/q?s=\'.strtoupper($symbol).\'&d=v1\';    
    $fd = fopen(\"$targetURL\", \"r\");        
    while (!feof($fd)) {
        $buffer = fgets($fd, 2048);
        if (strstr($buffer, \"<td nowrap><b>\")) {
            echo \"<tr><td>\".cleanUpText($buffer, strtolower($symbol)).\"</tr>\";
        }
    }
    fclose($fd);
}

if($submit){ ?>

    <table width=\"100%\">
    <tr>
        <td><b>Symbol:</b></td>
        <td><b>Time:</b></td>
        <td><b>Last:</b></td>
        <td><b>Change:</b></td>
        <td><b>Change (%):</b></td>
        <td><b>Volume:</b></td>
    </tr>

<?    for ($i=0; $i<count($symbol); $i++) {
        if ($symbol[$i] != \"\") {
            getQuote($symbol[$i]);
        }
    }
    echo \"\\n</table>\";
    echo \'<hr width=\"100%\">\';
}
?>

</body>
</html>

Comments or questions?
PX is running PHP 5.2.17
Thanks to Miranda Productions for hosting and bandwidth.
Use of any code from PX is at your own risk.