preserveWhitespaces=false;
if(!$dom->load('http://rpc.weblogs.com/shortChanges.xml'))
{
print ("Error loading XML file
");
}
else print("XML file loaded
");
$xp=new DomXPath($dom);
/*config*/
define ("TABLENAME", "titles");
define ("HOST", "localhost");
define ("DATABASE", "rss");
define ("USER", "PeterPedal");
define ("PASSWORD", "XXXX");
function get_titles($xp)
{
$handle = @mysql_connect (HOST, USER, PASSWORD);
if ($handle)
{
echo "connection to db-host established
";
}
else
{
die ("cannot connect to db-host");
}
if (mysql_select_db(DATABASE, $handle))
{
echo ("
connection to database established
"); } else { echo ("cannot connect to $db"); } $title_array = array(); $titles=$xp->query("//weblog"); for ($i=0;$i<$titles->length;$i++) { $j=($i+1); $title=$xp->query("//weblog[$j]"); //weblog $j if (substr_count_array(utf8_decode($title->item(0)->getAttribute("name")))<2) { $sql = 'INSERT INTO titles (title) VALUES("'.$title->item(0)->getAttribute("name").'")'; //echo $sql; mysql_query($sql, $handle); } } } function substr_count_array( $haystack) { $unwanted_characters = array("?","%"); $count = 0; foreach ($unwanted_characters as $substring) { $count += substr_count( $haystack, $substring); } return $count; } get_titles($xp); ?>