Request URI - If URL contains X & does Not contain

2019-06-14 19:50发布

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

标签: php uri stripos
2条回答
来,给爷笑一个
2楼-- · 2019-06-14 20:03

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>';}
查看更多
在下西门庆
3楼-- · 2019-06-14 20:15

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>';
}
查看更多
登录 后发表回答