我有一个情况。我需要使用php在远程html页面中仅编辑元标记和<div id="container"></div>
的内容。
当用户从edit.php编辑远程html页面时,该过程是加载远程页面div#container
(编辑由html5的内容可编辑属性完成)并单击保存按钮,编辑页面发送html到服务器页面,说update_html.php
。
在update_html.php
中,如何打开pages/remote_page.html
并仅编写/更新div#container
和元标记中的内容?
答案 0 :(得分:0)
首先,在html文件中添加一些标记,例如<!-- container begin -->
和<!-- container end -->
。
其次,使用preg_replace将它们更改为您的内容。
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);