xjx424 Posted January 26, 2009 Share Posted January 26, 2009 Hi, I am trying to append a javascript file "image_list.js" which contains an array like this: var tinyMCEImageList = new Array( ["Robot", "media/robot.jpg"], ["Logo", "media/logo_over.jpg"]); I can append the file using this: $File = "lists/image_list.js";$Handle = fopen($File, 'a');$Data = "New Data Here";fwrite($Handle, $Data);fclose($Handle); I just cannot figure out how to add another entry into the arraychanging it to something like this: var tinyMCEImageList = new Array( ["Robot", "media/robot.jpg"], ["Logo", "media/logo_over.jpg"], ["Animals", "media/animals.jpg"], ["Cookies", "media/cookies.jpg"]); any help is appreciated.Thanks Link to comment Share on other sites More sharing options...
jeffman Posted January 26, 2009 Share Posted January 26, 2009 Append won't work. You have that last line to deal with.Try reading the file into a string. Chop the last two characters off the end of the string. Add your new data to the end of the string. Add ");" to the end of the string. Write the string to the file, overwriting what was already there. Link to comment Share on other sites More sharing options...
xjx424 Posted January 26, 2009 Author Share Posted January 26, 2009 That's pretty much what I came up with. Works well! $File = "lists/image_list.js";$content1 = implode("",file($File));$content2 = str_replace(");","",$content1);$content = str_replace("\r\n","",$content2);$new_content = "".$content.",\n[\"".$_POST['heading']."\", \"".$file_path."\"]);";$fp = fopen($File,"w");fputs($fp,$new_content);fclose($fp); Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.