我对这个有点陌生,这个问题让我抓狂。
标签"? "
欢迎指教…
$url = $_SERVER['REQUEST_URI'];
$active = 'class=""';
switch($url){
case('/SSPCorporate/index.php'):
$active[0] = ' class="active"';
break;
case('/SSPCorporate/about.php'):
case('/SSPCorporate/our-customers.php'):
case('/SSPCorporate/our-partners.php'):
case('/SSPCorporate/our-clients.php'):
case('/SSPCorporate/our-standards.php'):
case('/SSPCorporate/our-awards.php'):
$active[1] = ' class="active"';
break;
case('/SSPCorporate/solutions.php'):
$active[2] = ' class="active"';
break;
case('/SSPCorporate/services.php'):
$active[3] = ' class="active"';
break;
case('/SSPCorporate/sustainability.php'):
case('/SSPCorporate/what-are-we-doing.php'):
case('/SSPCorporate/what-can-you-do.php'):
case('/SSPCorporate/what-we-support.php'):
case('/SSPCorporate/references.php'):
$active[4] = ' class="active"';
break;
case('/SSPCorporate/healthcare.php'):
$active[5] = ' class="active"';
break;
case('/SSPCorporate/blog/'):
$active[6] = ' class="active"';
break;
case('/SSPCorporate/contact.php'):
$active[7] = ' class="active"';
break;
}
?>
echo($url);
?>
<nav>
<ul class="clearfix">
<li id="first" <?= $active[0] ?> <a href="index.php" class="Bold">Home</a></li>
<li <?= $active[1] ?> <a href="about.php" class="Bold">About</a></li>
<li <?= $active[2] ?> <a href="solutions.php" class="Bold">Solutions</a></li>
<li <?= $active[3] ?> <a href="services.php" class="Bold">Services</a></li>
<li <?= $active[4] ?> <a href="sustainability.php" class="Bold">Sustainability</a></li>
<li <?= $active[5] ?> <a href="healthcare.php" class="Bold">Healthcare</a></li>
<li <?= $active[6] ?> <a href="/blog/" class="Bold">Blog</a></li>
<li id="last" <?= $active[7] ?> <a href="contact.php" class="Bold">Contact</a></li>
</ul>
</nav>
可能是PHP的short_open_tag
指令被禁用。
这实际上是一件好事,因为它们会导致代码的可移植性降低,不应该使用。
我建议用<?php echo $active[0] ?>
代替
很可能您的服务器没有配置为支持短标记<? {code} ?>
。试着用<?php {code} ?>
替换它们。您也可以启用短标记,但不推荐使用。
检查PHP指令short_open_tag
。如果它可能关闭,这是导致东西开始不执行的原因。
然而,使用它们根本不好,用<?php
替换将是更好的解决方案
大胆尝试,
<li <? echo $active[1]..
可以,因为短标记可能没有在服务器的PHP配置中启用。