我需要從我的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