dongzhan1570 2013-12-18 19:07
浏览 19
已采纳

如何:PHP elseIf根据URL内容更改div

Issue: I have a php file that I do not have access to but I need to be able to format it. It generates several different pages depending on the search. I have been able to change a div using php if else statements in the header that the php calls to. (See Below)

What I would like to do is have a statement that will change the div depending on what is in the url, now the issue with this is that one of the pages I need to change, has the "submitIt" in the url which is what I am using to change the first div.

I have tried to change the code so that it calls to a different portion of the url but because the url still contains the first bit "submitIt" it calls to that div, rather than the new div.

Is there a way to call the elseif statement where if it contains "submitIt and "MEDIA_TYPE_ID" then it would print out the new div?

<?php $url = $_SERVER["REQUEST_URI"];
if (strpos($url, "submitIt"))  {
echo '<div style="width:560px;" class="app-h3 app-table">';
}elseif (strpos($url, "MEDIA_TYPE_ID"))  {
echo '<div style="width:560px;" class="app-h3 app-table-none">';
}else {
echo '<div style="width:560px;" class="app-h3">';
}
?>
  • 写回答

1条回答 默认 最新

  • dongxiaofa6359 2013-12-18 19:12
    关注

    I think you are looking for the && operator. It means 'and'.

    if (strpos($url, "submitIt") && strpos($url, "MEDIA_TYPE_ID")) {
        // do something
    }
    

    If both of those are true, it will execute the code block.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 蓝桥oj3931,请问我错在哪里
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染