Answer the question
In order to leave comments, you need to log in
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()
}
);
});
file_put_contents('index.html', $_POST['content']);
Answer the question
In order to leave comments, you need to log in
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 questionAsk a Question
731 491 924 answers to any question