NightFalcon90909 Posted March 26, 2009 Share Posted March 26, 2009 Greetings! I have a new problem. =] I need to append some code to a .js file. .js file appears like this: var data = { 'var' : [ {info}, {info}, {info}, {info} ] } I need to insert {info} clauses from user generated input. I far as I can see, there is no clear way to do this. fopen() modes to append include a, and a+, but none of those let me do anything more than append text to the end. This would be fine, but I have that annoying ]} at the end which would end the variable before the stuff I would add. Is there a way I can somehow add new {info} clauses to my .js file with PHP, and if so, how? Thanks so much, I appreciate your time. Joseph Link to comment https://forums.phpfreaks.com/topic/151157-how-to-append-to-the-middle-of-a-file/ Share on other sites More sharing options...
Guest Xanza Posted March 26, 2009 Share Posted March 26, 2009 If anything I would include the data from a text file... Or maybe even a CSV database... Not really any direct way to do what you're asking. Link to comment https://forums.phpfreaks.com/topic/151157-how-to-append-to-the-middle-of-a-file/#findComment-794087 Share on other sites More sharing options...
NightFalcon90909 Posted March 26, 2009 Author Share Posted March 26, 2009 Technically couldn't I read the whole file, search and destroy the ]}, and append ", {info} ]}" I like that idea... How do I read the entire file into a var though? The file() would put it into an array. Is there some sort of arrayToString() command I could use? Link to comment https://forums.phpfreaks.com/topic/151157-how-to-append-to-the-middle-of-a-file/#findComment-794097 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.