这是我的代码......
if($_SERVER['REQUEST_URI'] == '/shop/category/handheld-thermal-imaging/')
{
echo
'<div class="current-mark"></div><div class="top-level"><a href="/shop/category/handheld-thermal-imaging/">HANDHELD<br />THERMAL IMAGING</a></div>';
}
else if($_SERVER['REQUEST_URI'] == '/shop/category/mobile-imaging/')
{
echo
'<div class="current-mark"></div><div class="top-level"><a href="/shop/category/mobile-imaging/">MOBILE IMAGING</a></div>';
}
基本上,此代码会显示不同的左侧网站导航,具体取决于您在网站上的哪个页面。它使用PHP REQUEST_URI功能通过页面的URL检测您所在的页面。
我的问题是,如何让代码检测同一导航片段的多个网址?
我试过这段代码......
if($_SERVER['REQUEST_URI'] == '/shop/category/handheld-thermal-imaging/' , '/shop/iphone-thermal-imaging-adapter/')
{
但该代码似乎不起作用。基本上我想弄清楚的是我如何使用REQUEST_URI'if'语句的多个URL。提前谢谢!
答案 0 :(得分:2)
将网址放入数组然后......
if(in_array($_SERVER['REQUEST_URI'],$array))
答案 1 :(得分:1)
你应该......切换到一个switch
语句,它既简洁又提供此选项:
switch($_SERVER['REQUEST_URI']) {
case '/shop/category/handheld-thermal-imaging/':
// THERE IS NO CODE AT ALL HERE!
// The absence of a "break;" causes control to "fall through" to the next
case '/shop/iphone-thermal-imaging-adapter/':
echo "something common for the thermal imaging urls";
break;
case 'some other url':
echo "something for the url that stands alone";
break;
}
答案 2 :(得分:1)
我使用OR语句进行了多个URL检查
<?php
if ((strpos($_SERVER['REQUEST_URI'], 'contact.php') || strpos($_SERVER['REQUEST_URI'], 'register.php') || strpos($_SERVER['REQUEST_URI'], 'login.php')) === false) {
echo "show";
} else {
echo "hide";
}
?>
答案 3 :(得分:0)
您可以在条件中使用“OR”语句:
if($_SERVER['REQUEST_URI'] == "whatever" || $_SERVER['REQUEST_URI'] == 'something else")
{
}