PHPを使用してXMLサイトマップを動的に生成しています。生成部分はスムーズに実行されていますが、結果をXMLファイルとして保存できません。ここで私が書いたPHPの:PHPを使用して動的に生成されたXMLサイトマップを保存できません
$xml = new SimpleXMLElement('<?xml version="1.0" encoding="utf-8" ?><urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd"/>');
$node = $xml->addChild('url');
$node->addChild('loc', 'http://www.pb.com/blog/');
$node->addChild('changefreq', "daily");
$node->addChild('priority', "1");
$connect = dbconn(PROJHOST, POSTSDB, POSTSUSR, POSTSPWD);
$sql = "SELECT * FROM tblposts ORDER BY id";
$query = $connect->prepare($sql);
if($query->execute()) {
$rows = $query->fetchAll(PDO::FETCH_ASSOC);
if($rows){
foreach($rows as $row){
$post_date = $row['post_date'];
$node = $xml->addChild('url');
$node->addChild('loc', trim("http://www.pb.com/blog/" . $row['post_name']));
$node->addChild('lastmod', str_replace(' ', 'T', $row['post_date']) . "-05:00");
$node->addChild('changefreq', "weekly");
$node->addChild('priority', "0.6");
}
}
}
Header('Content-type: text/xml');
print($xml->asXML());
// $dom->preserveWhiteSpace = FALSE;
$xml->save('sitemap.xml');
致命的なエラーそれは投げがある:未定義のメソッドにSimpleXMLElementに
コール::セーブ() /xxx/xxx/xxx/sandboxgenerate_sitemap.phpでオンライン79
代替手段はありますか?
このような問題が発生したとき[訳注:マニュアルを読む。それは何ですか?](http://php.net/manual/en/book.simplexml.php)___保存方法はどこですか? Nowhere – RiggsFolly
うわー。言い訳はしないが、無礼は本当に正当ではなかった。しかし、助けてくれてありがとう。 – TheLearner
PHPの 'file_put_contents()'関数を使ってファイルに書き込みます。 – mike510a