【问题标题】:Removing activex from html [duplicate]从html中删除activex [重复]
【发布时间】:2013-04-10 10:41:47
【问题描述】:

我有一个我正在尝试编写的 php 脚本。该脚本假设将 html 文件作为字符串打开并解析字符串的标签。我想删除对象标签之间的所有内容以及它们自己的标签。一旦完成解析 id 就像它保存文件一样。这是我到目前为止的代码。

<?php
$handle = file_get_contents("index.htm", "r");
#$str = preg_replace("/<object[0-9 a-z_?*&=\":\-\/\.#\,<>\\n\\r\\t]+<\/object>/smi", "", >             $str);
strip_tags("<object>", "</object>")
print "$handle"
?>

【问题讨论】:

  • 你可以看看 HTMLPurifier。 htmlpurifier.org
  • 不要使用正则表达式。你最终会完全破坏你的文档。使用DOM 可以轻松删除标签及其内容
  • 我将研究这两种方法。谢谢大家。

标签: php html string parsing activex


【解决方案1】:

这里是代码

             include './simple_html_dom.php';
            // replace this url with your file url
            $file = "http://localhost:8012/PhpProject1/file.html";
            $html = file_get_html($file);
            foreach($html->find('object') as $element) 
            {
                            $element->outertext = '';
            }
            // this is your html without Object tags 
            echo $html;

PHP Simple HTML DOM Parser Library下载库

希望它会起作用

【讨论】:

  • 效果很好,但如何用新输出覆盖现有文件?
  • 只是简单的php文件@Dk6861636b
猜你喜欢
  • 2014-05-07
  • 2017-05-22
  • 2012-12-29
  • 1970-01-01
  • 2011-09-04
  • 2023-04-02
  • 1970-01-01
  • 1970-01-01
  • 2018-06-24
相关资源
最近更新 更多