function add_to_playlist ($songName, $artistName, $songFile){$title = $songName;$creator = $artistName;$location = "../uploads/misc/".$songFile;$somecontent = '<playlist version="1" xmlns="http://xspf.org/ns/0/">' . "\n\t" . '<trackList>' . "\n\t\t<track>\r\t\t\t" . '<title>'.$title.'</title>' . "\n\t\t\t" . '<creator>'.$creator.'</creator>' . "\n\t\t\t" . '<location>'.$location.'</location>' . "\n\t\t" . '</track>' . "\n\n";$playlist = '../mp3/playlist.xml';$inhandle = fopen($playlist, "rb");$contents = fread($inhandle, filesize($playlist));fclose($inhandle);$exploded = explode("\n", $contents);// Let's make sure the file exists and is writable first.if (is_writable($playlist)) { // In our example we're opening $inhandle in append mode. // The file pointer is at the bottom of the file hence // that's where $somecontent will go when we fwrite() it. if (!$handle = fopen($playlist, 'wt')) { echo "Cannot open file ($playlist)"; exit; } // Write $somecontent to our opened file. if (fwrite($handle, $somecontent) === FALSE) { echo "Cannot write to file ($playlist)"; exit; } for ($i = 9; $i < 1000; $i++) { fwrite($handle, $exploded[$i]); } fclose($handle);} else { echo "The file $playlist is not writable";}}