不要显示此如果URL中包含以下(Don't show this if the url con

2019-07-30 16:57发布

我有一个简单的div我不希望加载如果访问者加载了一定的URL。

它看起来像这样:

<?php
if( stristr($_SERVER['PHP_SELF'], 'blog') == FALSE  )
{

echo "<div id="stuff"></div>";

}
?>

问题是...当我加载了www.url.com/blog在div#东西仍显示它不工作...。

我只是缺乏睡眠或应上述工作? 你会怎么做,如果URL中包含的博客没有一个div显示?

Answer 1:

尝试$_SERVER['REQUEST_URI']而不是:

if (substr($_SERVER['REQUEST_URI'], 0, 5) !== '/blog') {
    echo '<div id="stuff"></div>';
}

REQUEST_URI包含请求的URI路径和查询,而不仅仅是当前执行脚本一样的文件名PHP_SELF一样。



Answer 2:

OP的版本为我工作。 前提是你解决回声()语法错误。

echo "<div id=\"stuff\"></div>";

在PHP版本5.2.9测试



Answer 3:

尝试使用===运营商按2号例如:

http://us2.php.net/manual/en/function.stristr.php



文章来源: Don't show this if the url contains the following
标签: php wordpress