如何在php中删除html标签?
问题描述:
我想在我的cmd值=比较时删除这段代码,我该怎么做?如何在php中删除html标签?
这里是我的代码:
<h1 style="margin-top:24px;"><?=ucfirst($_GET['page5'])?><? if($_POST['mode']=='test' || $_GET['mode']=='test') { print " (Test Mode)"; } ?></h1>
if($_GET['cmd']=='compare' && !$_POST)
{
}
我用这个代码:
$dom = str_get_html($html);
// ...or construct dom from file/url
$dom = file_get_html($path);
// strip h1 tags (and their content)
foreach ($dom->find('h1') as $node) {
$node->outertext = '';
}
我如何删除上面的代码在CMD =由具有比较
答
(如果我有很好的理解你的问题。) 我无法检查的确切语法和PHP是不是我的主要语言,但是这件事情我已经做了我会像这样写
if($_GET['cmd']=='compare' && !$_POST)
{
[here comes the optional HTML code, may inclu php parts et]
}
因此,如果条件不符合,代码将不会显示。
答
你可以尝试实现这一目标您的“测试模式”Cookie。 使用setCookie("name","value",time() + 60);
这将为您的测试模式创建1分钟长的cookie。
然后添加一个附加条件: if($_COOKIE['name']) { // CONTENT }