dtf0925 2018-10-13 10:23
浏览 631
已采纳

检查URL是否包含特定路径的语句?

Is there an if statement that allows me to check whether a URL contains a particular path?

In my particular case (using wordpress), I'm trying to check wether the URL contains /store/ https://www.website.com.au/store/brand/ So there might be something after that path...

Thank you for your help!

  • 写回答

2条回答 默认 最新

  • douan3182 2018-10-13 10:38
    关注

    I suggest using WordPress function like is_singular, is_tax, etc..

    function get_current_url()
    {
        $pageURL = 'http';
        if (isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] == "on") {
            $pageURL .= "s";
        }
        $pageURL .= "://";
        if ($_SERVER["SERVER_PORT"] != "۸۰") {
            $pageURL .= $_SERVER["SERVER_NAME"] . ":" . $_SERVER["SERVER_PORT"] . $_SERVER["REQUEST_URI"];
        } else {
            $pageURL .= $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"];
        }
        return $pageURL;
    }
    
    $url = get_current_url();
    
    if (strpos($url, '/store/') !== false) {
        echo 'found';
    }else{
        echo 'not found';
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料