<?
/*
 * phpMSNBC-0.1.beta.php
 *
 * (GPL) 2002 by Hidayet Dogan (hdogan@hido.net)
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2, or (at your option)
 * any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 */

    #
    # If your connection is too slow, increase time out limit
    #

    
$timeout 10# seconds

    
$category[WLD]      = "News";
    
$category[COM]      = "Business";
    
$category[SPT]      = "Sports";
    
$category[LIF]      = "Living & Travel";
    
$category[HEALTH]      = "Health";
    
$category[ST]      = "Technology & Science";
    
$category[OA]      = "TV News";
    
$category[OP]      = "Opinions";
    
$category[WEA]      = "Weather";
    
$category[NWSFHIDDEN] = "Newsweek";

    
$fp = @fsockopen("www.msnbc.com"80$errno$errstr$timeout);

    if (!
$fp)
    die(
"ERROR ($errno): $errstr");

    
fputs($fp"GET /news/alert2.txt HTTP/1.0\r\n");
    
fputs($fp"HOST: www.msnbc.com\r\n");
    
fputs($fp"ACCEPT: */*\r\n"); 
    
fputs($fp"User-Agent: MSNBC-News-Alert/3.0\r\n\r\n");
    
$i 0;

    while (!
feof($fp)) {
    
$line fgets($fp8192);
    
$line trim($line);

    if (empty(
$line))
        continue;

    
$data explode("="$line2);

    switch (
$data[0]) {
        case 
"GMT":
        
preg_match("#(\d+)\.(\d+)\.(\d+) (\d+)\.(\d+)#si"
               
$data[1], $date);
        
$gmt mktime($date[4], $date[5], 0$date[2], $date[3],
                  
$date[1]);
        break;

        case 
"VER":
        
$version $data[1];

        case 
"U":
        
$news[$i][url] = "http://www.msnbc.com".str_replace("./"""$data[1]);
        break;

        case 
"H":
        
$news[$i][subject] = $data[1];
        break;

        case 
"A":
        
$news[$i][summary] = $data[1];
        break;

        case 
"S":
        
$news[$i][category] = $category[$data[1]];
        break;

        case 
"T":
        
$news[$i][sub] = $data[1];
        break;

        case 
"P":
        
$year   substr($data[1], 04);
        
$month  substr($data[1], 42);
        
$day    substr($data[1], 62);
        
$hour   substr($data[1], 82);
        
$minute substr($data[1], 102);
        
$second substr($data[1], 122);
        
$news[$i][publish] = date("l, F d, Y g:i a"mktime($hour$minute
                      
$second$month$day$year));
        break;

        case 
"E":
        
$i++;
        break;
    }
    }

    
fclose($fp);
?>
<b>phpMSNBC 0.1.beta sample output:</b>
<hr>
<?
foreach ($category as $val) {
    echo 
"<b>$val</b>\n<ul>\n";

    foreach (
$news as $item) {
    if (
$item[category] == $val)
        echo 
"<li>".((!empty($item[sub])) ? "<b>$item[sub]:</b> " "").
         
"<a href=\"$item[url]\">$item[subject]</a> ($item[publish])".
         
"<br>\n$item[summary]</li>\n";
    }

    echo 
"</ul>\n";
}
?>