Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/270.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 嵌套条件需求_Php_If Statement_Conditional Statements_Strip Tags - Fatal编程技术网

Php 嵌套条件需求

Php 嵌套条件需求,php,if-statement,conditional-statements,strip-tags,Php,If Statement,Conditional Statements,Strip Tags,必须有一种更有效的方法来编写这段代码(见下文)。有人能提供一种更有效地显示多个Ifs的解决方案吗 if ( isset($_POST["submit"]) || isset($_POST["submit_x"]) ) { // strip_tags removes tags and then we compare to the original contents if (strip_tags($_POST['fld_comments']) !== $_POST

必须有一种更有效的方法来编写这段代码(见下文)。有人能提供一种更有效地显示多个Ifs的解决方案吗

if (  isset($_POST["submit"])  
   || isset($_POST["submit_x"])
   ) {

    // strip_tags removes tags and then we compare to the original contents
    if (strip_tags($_POST['fld_comments']) !== $_POST['fld_comments']) {

        // Drop post as it had html in it (!==  means Not Identical )
        echo '<h2>No html tags allowed in comments</h2>';
        $blindError = true;  

    } else {

        // run secondary code such to process form

    }
}
if(设置($\u POST[“提交”]))
||isset($_POST[“提交”])
) {
//strip_标签删除标签,然后与原始内容进行比较
如果(带标签($\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\{
//删除包含html的帖子(!==表示不相同)
echo“评论中不允许使用html标记”;
$blindError=true;
}否则{
//运行辅助代码,如处理表单
}
}

您的代码绝对优秀且高效。我看不出有什么问题,嗯,你可以少用一点括号,但没什么大不了的

我的意思是:

if (isset($_POST["submit"]) || isset($_POST["submit_x"])) {

你为什么不直接从评论中去掉标签并保存呢?是什么让你想拒绝它呢?缩进(我为你添加的)使它更具可读性,而且故障排除要容易得多。我原以为检查页面是否基于帖子可以以某种方式与删除标签检查结合起来。-杰瑟曼:我可以拒绝帖子,但不想简单地删除标签,然后进行处理,因为代码的要点是检查机器人创建的垃圾邮件帖子,不允许它们删除这个问题似乎离题了,因为它是关于代码优化的。同意。我自己更喜欢交替语法if():和endif@jtheman通常检查发布的值和打印HTML不会在同一个地方。我也更喜欢HTML的替代语法,但他的代码对于他所需要的仍然是好的。@AD7six Dammit,谢谢:D。