1

我要做的是使用 PHP 的 simpleXML 函数将 RSS XML 提要导入 MySQL 数据库。但是 PHP 脚本唯一要做的就是将 0 写入我的数据库。我在做什么错?

示例 rss.xml

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<?xml-stylesheet title="XSL_formatting" type="text/xsl" href="/divers/rss/xslt.php" ?> 
<rss version="2.0"  xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
       <title></title>
       <link></link>
       <description></description>
   <lastBuildDate></lastBuildDate>
   <ttl></ttl>
   <item>
       <title></title>
       <description></description>
       <link></link>
       <guid></guid>
       <pubDate></pubDate>
   </item>
</channel>
</rss>

PHP

<?php

  include ('config.php'); 

  $xml_file = "http://xml.xml/rss.xml";
  $xml_load = simplexml_load_string(file_get_contents($xml_file));

  $link = (string)$xml_load->link;
  $guid = (string)$xml_load->guid;

  $sql = "INSERT INTO table (link,guid) VALUES('$link','$guid');";

  mysql_query($sql) or die("Error ".mysql_error());

?>
4

1 回答 1

0

这就是我正在做的事情:

$sxml = simplexml_load_file($feedURL); // loads in simple xml format

        foreach ($sxml->entry as $entry) {
            $title = stripslashes($entry->title);
            $summary = stripslashes($entry->summary);
        }

如您所见,我使用stripsplashes().

我想它看起来像:

foreach($xml->item as $item) {
  $link = stripslashes($item->link);
  $guid = stripslashes($item->guid);
}
于 2013-01-05T19:55:08.937 回答