我需要从我的php代码创建xml文件的帮助。我创建了一个函数,它根据需要形成xml,但我不知道如何将文件中形成的xml保存。从php创建xml文件的问题
此外,如果你还可以告诉我,下次如何更新已经创建的XML文件。
我的代码看起来像下面:
public function create_xml()
{
$output = "<?xml version=\"1.0\" encoding=\"utf-8\" ?> ";
$output .= "<data>";
$output .= "<news>";
$news_articles = new C7_News();
$db = C7_Bootstrap::getDb();
$foxsport_sql = "SELECT headline, link FROM c7_news
WHERE source = 'foxsports' AND category = 'Breaking News'
LIMIT 0,4";
$foxsport_rowset = $db->fetchAll($foxsport_sql);
$data = array();
foreach($foxsport_rowset as $foxsport_row)
{
$output .= "<title>";
$output .= "<description>";
$output .= "<![CDATA[";
$output .= $foxsport_row['headline'];
$output .= "]]>";
$output .= "<link>";
$output .= $foxsport_row['link'];
$output .= "</link>";
$output .= "</title>";
}
$output .= "</news>";
$output .= "</data>";
}
我可能会做错事太多,PLZ让我知道创建XML的最好方法。
谢谢 Zeeshan