새 게시물이 생성 될 때마다 자체 RSS를 생성하는 기존 웹 사이트가 있습니다. 모든 것은 PHP 4를 사용하는 서버에서 작동했지만 호스트가 PHP 5로 변경 되었기 때문에 항상 "잘못된 형식의 XML"이 있습니다. xml_parser_create() 및 xml_parse (...) 및 fwrite (..)를 사용하여 모든 것을 저장했습니다.PHP - RSS builder
다음은 저장시의 예입니다 (구형 RSS 라인을 추가하기 전에 읽습니다).
function SaveXml()
{
if (!is_file($this->getFileName()))
{
//Création du fichier
$file_handler = fopen($this->getFileName(),"w");
fwrite($file_handler,"");
fclose($file_handler);
}//Fin du if
//Header xml version="1.0" encoding="utf-8"
$strFileData = '<?xml version="1.0" encoding="iso-8859-1" ?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>'.$this->getProjectName().'</title><link>http://www.mywebsite.com</link><description>My description</description><lastBuildDate>' . date("r"). '</lastBuildDate>';
//Data
reset($this->arrData);
foreach($this->arrData as $i => $value)
{
$strFileData .= '<item>';
$strFileData .= '<title>'. $this->GetNews($i,0) . '</title>';
$strFileData .= '<pubDate>'. $this->GetNews($i,1) . '</pubDate>';
$strFileData .= '<dc:creator>'. $this->GetNews($i,2) . '</dc:creator>';
$strFileData .= '<description><![CDATA['. $this->GetNews($i,3) . ']]> </description>';
$strFileData .= '<link><![CDATA['. $this->GetNews($i,4) . ']]></link>';
$strFileData .= '<guid>'. $this->GetNews($i,4) . '</guid>';
//$strFileData .= '<category>'. $this->GetNews($i,5) . '</category>';
$strFileData .= '<category>Mycategory</category>';
$strFileData .= '</item>';
}//Fin du for i
$strFileData .= '</channel></rss>';
if (file_exists($this->getFileName()))//Détruit le fichier
unlink($this->getFileName());
$file_handler = fopen($this->getFileName(),"w");
fwrite($file_handler,$strFileData);
fclose($file_handler);
}//Fin de SaveXml
내 질문은 : 어떻게 만들고 PHP에서 RSS를 채울 수 있습니까?
피드 예제가 크게 도움이 될 것입니다. – ceejayoz
완료, 내 코드 스 니펫을 넣었습니다 –