here is my slashdot code see if this will help
<?
require "slashwatch.inc";
$backend = "http://slashdot.org/slashdot.xml";
$siteid = "7564f467ef0cbb0c8415db848eaf1861";
$stable = "Sites";
$fpread = fopen($backend, 'r');
if(!$fpread) {
// Log failed connection to site
// echo "$errstr ($errno)<br>\n";
// exit;
} else {
$connection = mysql_connect($hostname, $username, $password) OR die("Unable to connect to database");
@mysql_select_db( "$dbName") or die( "Unable to select database");
while(!feof($fpread) ) {
$buffer = ltrim(Chop(fgets($fpread, 256)));
if (($buffer == "<story>")) {
// Chop each line into appropiate variable
$title = ltrim(Chop(fgets($fpread, 256)));
$link = ltrim(Chop(fgets($fpread, 256)));
$time = ltrim(Chop(fgets($fpread, 256)));
$author = ltrim(Chop(fgets($fpread, 256)));
$depart = ltrim(Chop(fgets($fpread, 256)));
$topic = ltrim(Chop(fgets($fpread, 256)));
//#$time = time();
//$time = date("F j, Y, g:i a");
// Reg Ex Statements to Strip XML away
$title = ereg_replace( "<title>", "", $title );
$title = ereg_replace( "</title>", "", $title );
$link = ereg_replace( "<url>", "", $link );
$link = ereg_replace( "</url>", "", $link );
$time = ereg_replace( "<time>", "", $time);
$time = ereg_replace( "</time>", "", $time);
$topic = ereg_replace( "<topic>", "", $topic);
$topic = ereg_replace( "</topic>", "", $topic);
$description = $topic;
// Used to allow apstrophes in the database
$title = ereg_replace( "'", "\'", $title );
$description = ereg_replace( "'", "\'", $description );
// Check if headline is already in the database
$checkquery = "SELECT * FROM $table WHERE title = '$title' AND link = '$link'";
$checkresult = MYSQL_QUERY($checkquery);
// Insert if it isn't in database already
if(MYSQL_NUM_ROWS($checkresult) == 0){
$session = md5(uniqid(rand()));
$query = "INSERT INTO $table VALUES('$session','$title','$link','$description','$time','$siteid')";
//#$query = "INSERT INTO $table SET id = '$session', title = '$title', link = '$link', description = '$description', hdate = '$time', site_id = '$siteid'";
$result = MYSQL_QUERY($query);
$sqltimeupdate = "UPDATE $stable SET last_update = '$time' WHERE site_id = '$siteid'";
MYSQL_QUERY($sqltimeupdate);
}
}
}
fclose($fpread);
mysql_close($connection);
}
#echo "Done! All Articles are now in the database.";
?>