如何使用 php 在 html 页面中编辑 div 和元标记
how to edit a div and meta tags in a html page using php
我这里有个情况。我只需要使用 php 在远程 html 页面中编辑元标记和 <div id="container"></div>
的内容。
过程是,当用户从edit.php编辑远程html页面时,加载远程页面的div#container
(编辑由html5的内容完成可编辑属性)并点击保存按钮,编辑页面发送 html 到服务器页面,比如 update_html.php
.
在update_html.php
这里,我怎样才能打开pages/remote_page.html
和write/update只有div#container
和meta标签中的内容?
首先,在您的 html 文件中添加一些标记,例如 <!-- container begin -->
和 <!-- container end -->
。
其次,使用 preg_replace 将它们更改为您的内容。
例如
$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);
我这里有个情况。我只需要使用 php 在远程 html 页面中编辑元标记和 <div id="container"></div>
的内容。
过程是,当用户从edit.php编辑远程html页面时,加载远程页面的div#container
(编辑由html5的内容完成可编辑属性)并点击保存按钮,编辑页面发送 html 到服务器页面,比如 update_html.php
.
在update_html.php
这里,我怎样才能打开pages/remote_page.html
和write/update只有div#container
和meta标签中的内容?
首先,在您的 html 文件中添加一些标记,例如 <!-- container begin -->
和 <!-- container end -->
。
其次,使用 preg_replace 将它们更改为您的内容。
例如
$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);