|
Posted by marcomputers on 04/14/06 19:58
Hi,
I'm trying to automatically update an existing rss podcast file using
php and the str_replace function.
Every time I add a media file, it should read the .rss file into a
string, take the closing </channel> and </rss> tags out of it, and add
the new rss file info to the end of the existing string, writing it
back to the rss file. However, str_replace will not replace the
</channel> and </rss> tags with ' '. I'm new to php, any help would be
appreciated.
Start Code:
----------------
$xmlFile = "/home2/kingshar/public_html/podcast_test.rss";
$xmlReadHandle = fopen($xmlFile, 'r') or die("Cannot open podcast
file");
$xmlFileContents = fread($xmlReadHandle, filesize($xmlFile));
fclose($xmlFile);
//Search and delete closing rss tag
str_replace('</rss>', '', $xmlFileContents);
//Search and delete closing channel tag
str_replace('</channel>', '', $xmlFileContents);
//Write existing data and new data to xml file
$newxmlFileContents = $xmlFileContents.
"\n<title>".$stitle."</title>\n<itunes:author>Author's
Name</itunes:author>\n<description>".$scripture."</description>\n<pubDate>".$store_sdate."</pubDate>\n<gui
isPermaLink=false>".$audioFile."</guid>\n<enclosure url=".$audioFile .
$audioSize ."type=audio/mpeg
/>\n<itunes:explicit>clean</itunes:explicit>\n</item>\n\n</channel>\n</rss>";
$xmlWriteHandle = fopen($xmlFile, 'w') or die("Cannot open podcast
file");
fwrite($xmlWriteHandle, $newxmlFileContents);
fclose($xmlFile);
[Back to original message]
|