dongyan7988 2015-01-24 03:03
浏览 37
已采纳

如何使用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?

  • 写回答

1条回答 默认 最新

  • dtdvbf37193 2015-01-24 03:17
    关注

    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);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#java#的问题,请各位专家解答!
  • ¥15 急matlab编程仿真二阶震荡系统
  • ¥20 TEC-9的数据通路实验
  • ¥15 ue5 .3之前好好的现在只要是激活关卡就会崩溃
  • ¥50 MATLAB实现圆柱体容器内球形颗粒堆积
  • ¥15 python如何将动态的多个子列表,拼接后进行集合的交集
  • ¥20 vitis-ai量化基于pytorch框架下的yolov5模型
  • ¥15 如何实现H5在QQ平台上的二次分享卡片效果?
  • ¥15 python爬取bilibili校园招聘网站
  • ¥30 求解达问题(有红包)