I just write code that automatic create xml file getting from databse . it look like this :
$model = new Playlists();
$playlists = $model->getAllPlaylists();
foreach($playlists as $playlist)
{
$songs = $model->getSongsByPlaylistId($playlist['playlist_id']);
/* create a dom document with encoding utf8 */
$dom = new DOMDocument('1.0', 'utf-8');
$rss = $dom->createElement('rss');
$dom->appendChild($rss);
$version = $dom->createAttribute('version');
$rss->appendChild($version);
$value = $dom->createTextNode('2.0');
$version->appendChild($value);
$xmlns_wp = $dom->createAttribute('xmlns:media');
$rss->appendChild($xmlns_wp);
$value = $dom->createTextNode('http://ift.tt/W3lYmr');
$xmlns_wp->appendChild($value);
$xmlns_dc = $dom->createAttribute('xmlns:jwplayer');
$rss->appendChild($xmlns_dc);
$value = $dom->createTextNode('http://ift.tt/1nwd89e');
$xmlns_dc->appendChild($value);
$channel = $dom->createElement("channel");
$channel = $rss->appendChild($channel);
/* you should enclose the following two lines in a cicle */
$channel->appendChild($dom->createElement('title',$playlist['playlist_title']));
foreach($songs as $song)
{
$item = $dom->createElement("item");
$item = $channel->appendChild($item);
$item->appendChild($dom->createElement('title',$song['song_title']));
$mediacontent = $dom->createElement('media:content');
$item->appendChild($mediacontent);
$url = $dom->createAttribute('url');
$mediacontent->appendChild($url);
$urlvalue = $dom->createTextNode('http://ift.tt/1lax9Xx'.$song['song_ember_code'].'.m4a');
$url->appendChild($urlvalue);
$item->appendChild($dom->createElement('jwplayer:downloadlink','http://ift.tt/1lax9Xz'.$song['song_name']));
}
/* get the xml printed */
$dom->save("C:/xampp/htdocs/xml_playlists/".$playlist['playlist_name'].".xml");
}
And the result look like this :
playlist1.xml
playlist2.xml
palylist3.xml
assuming , i edited playlist2 , i want it to immediately update to playlist2.xml . I tried crontab but it must run every second to ensure my xml always new when I edited, and it will updated all my xml file . I don't want to do it this way
I wonder if there is anyway better ? Any help will be appreciate
No comments:
Post a Comment