A
A
Alexander Sharomet2015-10-01 17:23:23
PHP
Alexander Sharomet, 2015-10-01 17:23:23

How to save content with php in body of html file?

Hello!
How can I save dynamic content in html file (body).
I used this method
, by clicking on the button we pass data to the post array from #maincontent

$('#save').click(function(){
    $.post('save.php',
      {
        content:$('#maincontent').html()
      }
    );
  });


save.php
file_put_contents('index.html', $_POST['content']);

I save the data in index.html

, the problem is that I will overwrite the data of the entire file, and I need them to simply be inserted into the body.

How can this be implemented? Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Valery Ryaboshapko, 2015-10-01
@sharomet

In general, the idea of ​​editing entire HTML files on the server side looks pretty vicious, it carries crutches a mile away.
But in general there are two options. The first is to have a template file that contains something like {{{PLACE_CONTENCT_HERE}}} inside the tag. This file is read, str_replace() is done on it, the result is written to the file.
The second way out is to use regular expressions. Read the file, use a regular expression to find everything that is inside the tag, replace and write back to the file.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question