現在、リモート サイトの XML フィードを取得し、ローカル コピーをサーバーに保存して PHP で解析しています。
問題は、PHP でいくつかのチェックを追加して、feed.xml ファイルが有効かどうかを確認し、有効な場合は feed.xml を使用する方法です。
エラーで無効な場合 (リモート XML フィードで空白の feed.xml が表示される場合があります)、以前のグラブ/保存からの feed.xml のバックアップの有効なコピーを提供しますか?
コード取得 feed.xml
<?php
/**
* Initialize the cURL session
*/
$ch = curl_init();
/**
* Set the URL of the page or file to download.
*/
curl_setopt($ch, CURLOPT_URL,
'http://domain.com/feed.xml');
/**
* Create a new file
*/
$fp = fopen('feed.xml', 'w');
/**
* Ask cURL to write the contents to a file
*/
curl_setopt($ch, CURLOPT_FILE, $fp);
/**
* Execute the cURL session
*/
curl_exec ($ch);
/**
* Close cURL session and file
*/
curl_close ($ch);
fclose($fp);
?>
これまでのところ、これをロードするだけです
$xml = @simplexml_load_file('feed.xml') or die("feed not loading");
ありがとう