为什么SSI条件!= || !=不起作用? [英] Why SSI condition != || != doesn't work?
问题描述
我无法使用此条件表达式
<! - #if expr =$ DOCUMENT_NAME!= index.html || $ DOCUMENT_NAME!= links.html - >
这个没有!
之前 =
完美无缺
<! - #if expr =$ DOCUMENT_NAME = index.html || $ DOCUMENT_NAME = links.html - >
有什么问题?我没有收到任何错误只是!=
虽然 ||
但其他条件不起作用,但适用于单一条件。<这是因为 =
和!=
几乎不是同一个运营商。请注意,通过 De Morgan定律(我也在这篇旧帖子中解释),
a!= b || c!= d
相当于
a = b&& c = d
永远不会为<$ c $ c> x = a&& x = b 其中 a!= b
。
更改二元运算符要求更改条件也是等效的。
因此,按照上述逻辑,
$ DOCUMENT_NAME!= index.html || $ DOCUMENT_NAME!= links.html
相当于
$ DOCUMENT_NAME = index.html&& $ DOCUMENT_NAME = links.html
无法为真,因为$ DOCUMENT_NAME可以是index.html或links.html,但不是两者。
然而,第二个片段,
$ DOCUMENT_NAME = index.html || $ DOCUMENT_NAME = links.html
有效,因为上面没有提到逻辑上永不正确的谬误。当$ DOCUMENT_NAME index.html或links.html时会是如此。
某些语言/值会违反上述等价物......但这是另一个主题。
I can't get working this conditional expression
<!--#if expr="$DOCUMENT_NAME!=index.html || $DOCUMENT_NAME!=links.html" -->
while this one without !
before =
works perfect
<!--#if expr="$DOCUMENT_NAME=index.html || $DOCUMENT_NAME=links.html" -->
What's the problem? I get no error simply !=
doesn't work though ||
with other condition but works for single condition.
This is because =
and !=
are hardly the same operator. Note that, by De Morgan's law (which I also explained in this old post),
a != b || c != d
is equivalent to
a = b && c = d
which is never true for x = a && x = b
where a != b
.
Changing the binary operator requires changing the conditionals as well to be equivalent.
Thus, by the above logic,
$DOCUMENT_NAME!=index.html || $DOCUMENT_NAME!=links.html
is equivalent to
$DOCUMENT_NAME=index.html && $DOCUMENT_NAME=links.html
which cannot be true as $DOCUMENT_NAME can be "index.html" or "links.html" but not both.
However, the 2nd snippet,
$DOCUMENT_NAME=index.html || $DOCUMENT_NAME=links.html
"works" because there is not the logical never-true fallacy mentioned above. It will be true when $DOCUMENT_NAME is either "index.html" or "links.html".
Some languages/values will violate the above equivalency .. but that is another topic.
这篇关于为什么SSI条件!= || !=不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!