代码之家  ›  专栏  ›  技术社区  ›  codeNinja

在PHP中读取已用javascript编码的URL

  •  -2
  • codeNinja  · 技术社区  · 6 年前

    在javascript中,我对请求参数的某些部分进行如下编码

    window.location.href = "search.php?qry=" + encodeURIComponent("m & l");
    

    在我的search.php中,我是这样找到这个的

    $url = urldecode($_SERVER['REQUEST_URI']);
    echo ."Full URL: " .$url ."<br>";
    $parts = parse_url($url);
    parse_str($parts['query'], $query);
    $qry = "Just Query: " .trim($query['qry']);
    echo $qry ."<br>";
    

    打印出:

    Full Url: /Search.php?qry=m & l
    Just Query: m
    

    看起来像是 & 正在删除“M&L”`

    我需要在php或javascript中做什么更改?

    1 回复  |  直到 6 年前
        1
  •  3
  •   EPB    6 年前

    $url = urldecode($_SERVER['REQUEST_URI']);
    

    $url = $_SERVER['REQUEST_URI'];
    

    parse_url

    $_GET['qry'] 'm & l'

    encodeURIComponent

    window.location.href = "search.php?qry=" + encodeURIComponent("m & l") + "&subcat="+encodeURIComponent("hello & there");