how to code a page with code?

how to code a page with code?

Let me explain...  I am trying to make a gui for clients to edit a php page that displays html and javascript.

I want the user to be able to move html elements around and even edit it like add effects like fade in and out etc.

Then after all the changes  I want to overwrite the existing php file that does this for that user. how can you make such changes and then save it to a file?

it's an html / javascript editor but  using a gui instead of allowing them to directly touch the code. It would be a security risk if I allow such a thing. So I need to program a interface that would make such changes and save them to file.

Like how can you delete  and add new javascript code to the file?