php中location.path值判断

php中location.path值判断

<?php if(strpos($_SERVER["REQUEST_URI"],'hospital') == 1){ ?>
    <img src="/images/hospital.png" />
<?php } elseif (strpos($_SERVER["REQUEST_URI"],'doctor') == 1){?>
    <img src="/images/doctor.png" />
<?php } elseif (strpos($_SERVER["REQUEST_URI"],'circle') == 1){?>
    <img src="/images/circle.png" />
<?php } ?>

  • 使用 $_SERVER["REQUEST_URI"] 从URL中取得path值('/hospital')。
  • 使用 strpos(string,find,start) 判断是否以'hospital' 开始。
  • 使用 elseif 而不是 else if

注意
使用 strpos($_SERVER["REQUEST_URI"],'/hospital') == 0 不能正确判断。

posted @ 2017-05-10 14:55  peng2015  阅读(449)  评论(0编辑  收藏  举报