问题
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