function write_rss() { global $post_data; $item = array('guid', 'title', 'pubDate', 'link', 'description'); $rss_filename = 'rss-blogfeed.xml'; // Check if RSS file exist if (file_exists($rss_file) && filesize($rss_file) != 0) { $rss_update = new DOMDocument(); $rss_update->load($rss_file); } else { try { $rss_file = new DOMDocument('1.0', 'utf-8'); $rss_file->formatOutput = true; //Create the rss tag and set the version 2.0 $rss_tag = $rss_file->crateElement('rss'); $rss_attr = $rss_file->createAttribute('version'); $rss_attr->value = '2.0'; //Append attribute to rss tag $rss_tag->appendChild($rss_attr); //Create channel $channel_element = $rss_file->createElement('channel'); //Create channel children and append to it. foreach ($channel as $channel_tag) { $t_chan = $rss_file->createElement($channel_tag); $channel_element->appendChild($t_chan); } //Create item $item_element = $rss_file->createElement('item'); //Create item children and append to it foreach ($item as $item_tag) { $t_item = $rss_file->createElement($item_tag); $item_element->appendChild($t_item); } //Append item to channel $channel_element->appendChild($item_element); //Append channel to rss $rss_tag->appendChild($rss_tag); //Append rss to file $rss_file->appendChild($rss_tag); $rss_file->save($rss_filename); } catch (Exception $e) { // Log error if failing } } }