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

时间:2015-01-24 03:03:20

标签: javascript php jquery html file

我有一个情况。我需要使用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和元标记中的内容?

1 个答案:

答案 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);