This simple script downloads the contents of the chatterbox XML ticker and parses all the messages into an array for easy manipulation. More details in the comment at the top of the script. Enjoy!


<?
/*****************************************************************************
 *
 * PHP Chatterbox Parser v0.1
 * by Ryan Grove
 * ryan@wonko.com
 * http://wonko.com/
 *
 * Parses the chatterbox XML ticker into a two-dimensional array ($chatter).
 * The following array values are set:
 *
 * $chatter[0]["author"]   Author of the message
 * $chatter[0]["time"]     Timestamp of the message
 * $chatter[0]["message"]  Text of the message
 *
 * Messages are not parsed for node titles (i.e., [node]) or for actions
 * (/me). I'll leave that up to you. Enjoy!
 *
 *****************************************************************************/

// URL of the E2 chatterbox XML ticker
$url = "http://everything2.com/index.pl?node=chatterbox+xml+ticker";

// Get chatterbox XML, put it into an array
$xml = file($url);      

// Parse the XML
$e = 0;
$chatter = array();
for($i=1;$i<(count($xml) -1);$i++) 
{
    if (strpos($xml[$i], "<message author=") !== false) 
    {
        $pos = (strpos($xml[$i], "author=\"") + 8);
        $chatter[$e]["author"] = substr($xml[$i], $pos, (strpos($xml[$i], "\"", $pos) - $pos));

        $pos = (strpos($xml[$i], "time=\"") + 6);
        $chatter[$e]["time"] = substr($xml[$i], $pos, (strpos($xml[$i], "\"", $pos) - $pos));           
    } 
    else 
    {
        $chatter[$e]["message"] = substr($xml[$i], 0, (strlen($xml[$i]) - 11));
        $e++;           
    }
}   
?>