PX : code

Yahoo Stock Quote Slurper by Juan Chico
Download this code


<?php
/*********************************************************************
Note: this doesn't work anymore ... it's dependent on the HTML layout
to parse out the stock quote image so I'll have to update this -- sorry
*/


function getYahooQuote($stockSymbol "CCR")
{
if (!
$targetURL$targetURL "http://finance.yahoo.com/q?s=$stockSymbol&d=t";    
    
$fd fopen("$targetURL""r");
    
$stopExtract 0
    
$startExtract 0
    while (!
feof($fd)) 
    {
        
$buffer fgets($fd4096);
            
//echo trim($buffer)."n"; 
        
if (strstr($buffer"rowspan=3"))
        {
            
//echo "extract started at line #$lineCountn"; 
            
$startExtract 1
        }    

        if (
$startExtract && !$stopExtract)    
        {
    
            if (
strstr($buffer"<a")) 
            {
                
$startPos strrpos($buffer"<");
                
$buffer substr($buffer$startPos);
            }
            
//$text = trim(strip_tags($buffer));
            //echo trim($buffer)."n"; 
        
            
$buffer str_replace("nr"" ""$buffer");
            if (
strstr($buffer"http://ichart.yahoo.com/v?s=$stockSymbol")) 
            {
                
//echo "ichart found!";
                
$stopExtract 1
            }
            
$capturedHTML .= $buffer;    
    
        }

        if (
$startExtract && strstr($buffer"<br>"))
        {
             
$stopExtract 1
            
//echo "extract stopped at line #$lineCountn";         
            
echo $capturedHTML;
            break;
        }
        
$lineCount++;
    }
    
fclose($fd);
}


//////////////////sample code///////////////////
$symbols = array('CCR''IIXL','SAPE','WBVN' );
$symbolCount count($symbols);
for (
$i=0$i$symbolCount$i++)
{
    echo 
"$symbols[$i]<br>";
    
getYahooQuote("$symbols[$i]");
}

?>

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.