-1

我有一个带有标题和描述的项目的 RSS 提要。我想将这些加载到表中

我有类似的东西,但它既没有回显任何东西,也没有插入任何东西。

 $con = mysql_connect("localhost","USERNAME","PASSWORD");
    if (!$con)
    {
        die('Could not connect: ' . mysql_error());
    }





$rss = simplexml_load_file('rss.xml');

foreach ($rss->item as $eachFilm) {
    $film_name = array($eachFilm->title);
    $film_release = array($eachFilm->description);
    echo $film_name;

    mysql_query("INSERT INTO Films (Film_Name, Film_Release)
VALUES ('$film_name', '$film_release')");

}

mysql_close($con);

任何帮助将非常感激!

编辑 - 示例 RSS -

</image><item>
             <title>Remembrance</title>
             <link>http://www.filmdates.co.uk/films/3950-remembrance/</link>
             <description><![CDATA[Release Date: Wednesday 18th April 2012]]></description>
             <category>Movie</category>
             <pubDate>Tue, 27 March 2012 20:31:29 MST</pubDate>
           </item><item>
             <title>In Search of Haydn</title>
             <link>http://www.filmdates.co.uk/films/3672-in-search-of-haydn/</link>
             <description><![CDATA[Release Date: Thursday 19th April 2012]]></description>
             <category>Movie</category>
             <pubDate>Mon, 16 April 2012 19:33:41 MST</pubDate>
           </item><item>
4

1 回答 1

0

well i don't know about you rss file that hows the complete structure of your Rss file is,

here is an quick example of a wordpress rss file with simplexml_load_file

$conn = mysql_connect("localhost", "*****", "****");
if($conn)
    mysql_select_db("test", $conn);

$rss = simplexml_load_file('file.xml');
$getChild = $rss->children();

foreach( $rss->children() as $item ){

    // Count Total Items in the Files
    $total_items = $item->item->count();
    for( $i=0; $i < $total_items; $i++ ){
        $title = $item->item[$i]->title;

        $query = mysql_query("insert into tbl_name (name) value ('$title')");
        if( $query ){
            echo "Inserted Success! <br>";
        }
        else{
            echo "Error in Query!<br>";
        }
    }
}

the above example will work with the wordpress xml file, that i have tested on my local and working perfectly. Hope this will help you.

于 2012-04-16T08:08:08.723 回答