u013478024 2023-02-07 00:34 采纳率: 60%
浏览 157
已结题

关于#php#根据url判断选择加载模板应该如何解决?会的速来捡钱!

拿到一套php程序,现在需要加几个判断,根据url中的参数决定打开的模板文件
目前运行没有错误,可以正常输出!
    function read_templates(){
    if($_SERVER['REQUEST_URI']=='/'||$_SERVER['REQUEST_URI']==''){
            $templates_content = file_get_contents('data/templates/index.html');

    }else{
        global $isspider;
          if($isspider==1) {
              
                  $templates_content = file_get_contents('data/templates/spider.html');
          }else{
            $templates_content = file_get_contents('data/templates/show.html');
          }
    }
        
        return $templates_content;
    }

目前没有报错!
自己不会写!
我想要 在$isspider 中添加判断:

1、在url中含有 “v-123.html” 则调用 v的模板,含有 “w-abc.html” 则调用 w的模板(v-和w-后面是表示任意字符和数字,所以只能能用v-或w-做判断)
2、若url中不含有 v-或w- 则指向一个域名或页面均可!

判断后能正常输出就行,会的相当于捡钱!佣金只给首位提供正确答案者!

  • 写回答

4条回答 默认 最新

  • 社区专家-Monster-XH 2023-02-07 00:52
    关注
    
    function read_templates(){
        if($_SERVER['REQUEST_URI']=='/'||$_SERVER['REQUEST_URI']==''){
            $templates_content = file_get_contents('data/templates/index.html');
     
        }else{
            global $isspider;
            if(preg_match('/v-[\w]+\.html/', $_SERVER['REQUEST_URI'])) {
                $templates_content = file_get_contents('data/templates/v.html');
            }else if(preg_match('/w-[\w]+\.html/', $_SERVER['REQUEST_URI'])) {
                $templates_content = file_get_contents('data/templates/w.html');
            }else if($isspider==1) {
                $templates_content = file_get_contents('data/templates/spider.html');
            }else{
                $templates_content = file_get_contents('data/templates/show.html');
            }
        }
            
        return $templates_content;
    }
    
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论 编辑记录
查看更多回答(3条)

报告相同问题?

问题事件

  • 系统已结题 2月15日
  • 已采纳回答 2月7日
  • 创建了问题 2月7日

悬赏问题

  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)