Request URI - If URL contains X & does Not contain Y - then do something

99封情书 提交于 2019-12-10 12:24:41

问题


Hi there my current code looks like this:

if (stripos($_SERVER['REQUEST_URI'],'cake') !== false) 
        {echo '<div class="clear"></div><a href="http://www.example.com/cakes/" class="btn"> >> View all Cakes</a>';}

This works well to check if the current URL contains the word 'cake' and Then display a link to all cakes.

What I need to add to this is:

If URL contains 'cake' but does not contain 'carrot' Then display a link to all cakes.

Any ideas on how I can modify?

Many Thanks


回答1:


You can try the below code :

if (stripos($_SERVER['REQUEST_URI'],'cake') == true && stripos($_SERVER['REQUEST_URI'],'carrot') == false) 
        {echo '<div class="clear"></div><a href="http://www.example.com/cakes/" class="btn"> >> View all Cakes</a>';}



回答2:


Just add one more condition:

if (stripos($_SERVER['REQUEST_URI'],'cake') !== false && stripos($_SERVER['REQUEST_URI'],'carrot') === false) {
    echo '<div class="clear"></div><a href="http://www.example.com/cakes/" class="btn"> >> View all Cakes</a>';
}


来源:https://stackoverflow.com/questions/32244509/request-uri-if-url-contains-x-does-not-contain-y-then-do-something

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!