robmarston Posted July 23, 2007 Share Posted July 23, 2007 Is it possible to use PHP to add/remove text from a flat file? Basically, what I'm attempting to do is have users click to add/remove (manage) songs from a dynamically generated XML playlist. I've used the file write command to generate a successful XML playlist file, but every time the form data is submitted, it overwrites the entire file. I want the user to be able to not only add songs, but remove old ones as well. I've considered simply adding or removing songs from a database table, but how then would I generate the playlist from database information? PLEASE HELP! Please send help to: robmarston@hotmail.com - Thank you! Quote Link to comment Share on other sites More sharing options...
Wildbug Posted July 23, 2007 Share Posted July 23, 2007 Yes, see the filesystem functions section of the PHP manual for a plethora of functions and examples. You can add to a file without overwriting the existing contents using an "append" mode instead of "write." Or you can read the file into memory, alter it, and write it out, overwriting the old version. Quote Link to comment Share on other sites More sharing options...
stlewis Posted July 24, 2007 Share Posted July 24, 2007 Actually, depending upon how expansive your information is going to become, you might consider using a database anyway. This seems like the kind of application that would need one...that way you could relationally store information about a particular item's author, genre, whatever...As for generating a playlist out of database information...You could technically query your database, and then output the queried data in to a flat file for use as a playlist: $q = "SELECT * FROM tbl_songs"; $q_result=mysql_query($q); //Open or create flat playlist file. $f_handle=fopen("playlist", "w+"); while ($q_array=mysql_fetch_assoc($q_result)) { //Feed the contents of the SQL query in to variable $content=$content.q_array[songName]; } //Write the final contents out to the flat file. fwrite($f_handle,$contents); Sorry if I'm misunderstanding you here! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.