Jump to content

How to append to the middle of a file


NightFalcon90909

Recommended Posts

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

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?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.