如何使用PHP编辑html页面中的div和meta标签

I have a situation here. I need to edit only meta tags and the contents of a <div id="container"></div> in a remote html page, using php.

The process is, when the user edits the remote html page from edit.php, which loads the remote page's div#container (editing is done by html5's content editable attribute) and clicks save button, the edit page sends the html to the server page, say update_html.php.

Here in update_html.php how can I open pages/remote_page.html and write/update only the contents in the div#container and the meta tags?

First, add some marks in your html file, such as <!-- container begin --> and <!-- container end -->.

Second, use preg_replace to change them to your content.

e.g.

$info = file_get_contents('pages/remote_page.html');
preg_replace('|(<!\-\- container begin \-\->.*<!\-\- container end \-\->)|isU', $_POST['content'], $info);
file_put_contents('pages/remote_page.html', $info);