Plug-in PHP Chapter 10, Plug-in 77 (Click on the icon to view the source for copy and pasting)
<?php // Plug-in 77: Get Yahoo! Stock News

// This is an executable example with additional code supplied
// To obtain just the plug-ins please click on the Download link

$stock   = "AAPL";
$results = PIPHP_GetYahooStockNews($stock);
echo "<font face='Arial' size='2'>Fetching recent news " .
     "stories for: <b>$stock</b>:<br /><br />";

if (!$results[0]) echo "No stories found for $stock.";
else
{
   echo "<a href='http://finance.yahoo.com/q?s=$stock'>".
        "<img src='" . $results[1][0] . "' border='1' />" .
        '</a><br /><br />';

   foreach($results[2] as $result)
      echo "<a href='$result[4]'>$result[0]</a> " .
           "($result[1], $result[2])<br />$result[3]" .
           '<br /><br />';
}

function PIPHP_GetYahooStockNews($stock)
{
   // Plug-in 77:  Get Yahoo! Stock News
   //
   // This plug-in takes a stock ticker symbol and then returns
   // any recent news stories on it from finance.yahoo.com.
   // Upon success it returns a three element array, the first
   // of which is the number of new stories returned, the second
   // is a two element array with a URL to a small (192x96) and
   // a large (512x288) intraday price chart for the stock,  and
   // the third element is an array in which each element
   // contains a sub-array of the following five items for each
   // stock: 1) The title of the news story, 2) The site it came
   // from, 3) The date of the story, 4) The story summary, and
   // 5) The URL of the original story. On failure a single
   // element array with the value FALSE us returned. It requires
   // this argument:
   //
   //    $stock: A stock symbol

   $stock = strtoupper($stock);
   $url   = 'http://finance.yahoo.com';
   $check = @file_get_contents("$url/q?s=$stock");

   if (stristr($check, 'Invalid Ticker Symbol') || $check == '')
      return array(FALSE);

   $reports = array();
   $xml     = file_get_contents("$url/rss/headline?s=$stock");
   $xml     = preg_replace('/&lt;\/?summary&gt;/', '', $xml);
   $xml     = preg_replace('/&lt;\/?image&gt;/',   '', $xml);
   $xml     = preg_replace('/&lt;\/?guid&gt;/',    '', $xml);
   $xml     = preg_replace('/&lt;\/?p?link&gt;/',  '', $xml);
   $xml     = str_replace('&lt;![CDATA[',          '', $xml);
   $xml     = str_replace(']]&gt;',                '', $xml);
   $xml     = str_replace('&amp;',      '[ampersand]', $xml);
   $xml     = str_replace('&',                '&amp;', $xml);
   $xml     = str_replace('[ampersand]',      '&amp;', $xml);
   $xml     = str_replace('<b>',          '&lt;b&gt;', $xml);
   $xml     = str_replace('</b>',        '&lt;/b&gt;', $xml);
   $xml     = str_replace('<wbr>',      '&lt;wbr&gt;', $xml);
   $sxml    = simplexml_load_string($xml);

   foreach($sxml->channel->item as $item)
   {
      $flag  = FALSE;
      $url   = $item->link;
      $title = $item->title;
      $temp  = explode(' (', $title);
      $title = $temp[0];
      $site  = str_replace(')', '', $temp[1]);
      $site  = str_replace('at ', '', $site);
      $desc  = $item->description;
      $date  = date('M jS, g:ia',
         strtotime(substr($item->pubDate, 0, 25)));

      for ($j = 0 ; $j < count($reports) ; ++$j)
      {
         similar_text(strtolower($reports[$j][0]),
            strtolower($title), $percent);

         if ($percent > 70)
         {
            $flag = TRUE;
            break;
         }
      }

      if (!$flag && !strstr($title, '[$$]') && strlen($desc))
         $reports[] = array($title, $site, $date, $desc, $url);
   }

   $url1 = "http://ichart.finance.yahoo.com/t?s=$stock";
   $url2 = "http://ichart.finance.yahoo.com/b?s=$stock";
   return array(count($reports), array($url1, $url2), $reports);
}

?>