dongposhi8677 2018-07-01 17:19
浏览 160
已采纳

php解析字符串而不解码

My $_SERVER['QUERY_STRING'] returns this:

route=common/home/test/aHR0cHM6Ly93d3cueW91dHViZS5jb20vd2F0Y2g%2Fdj1iZWsxeTJ1aVFHQQ%3D%3D/456&param2=test

As we can see that there is base64 encoded string passed with get request. I want to parse route parameter without decoding its value.

I need this one:

common/home/test/aHR0cHM6Ly93d3cueW91dHViZS5jb20vd2F0Y2g%2Fdj1iZWsxeTJ1aVFHQQ%3D%3D/456

Not this one:

common/home/test/aHR0cHM6Ly93d3cueW91dHViZS5jb20vd2F0Y2g/dj1iZWsxeTJ1aVFHQQ==/456

I tried to parse route parameter with parse_str function. But it decoded the route's value.

  • 写回答

2条回答 默认 最新

  • dongqiancui9194 2018-07-01 18:27
    关注

    You could essentially replicate parse_str but without applying urldecode:

    $x = $_SERVER['QUERY_STRING'];
    $y = explode('&', $x);
    
    $qs = [];
    
    foreach($y AS $z) {
        list($key, $val) = explode('=', $z);
        $qs[$key] = $val;
    }
    

    Which should give you

    array(2) {
      ["route"]=> string "common/home/test/aHR0cHM6Ly93d3cueW91dHViZS5jb20vd2F0Y2g%2Fdj1iZWsxeTJ1aVFHQQ%3D%3D/456"
      ["param2"]=> string "test"
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥50 随机森林与房贷信用风险模型
  • ¥50 buildozer打包kivy app失败
  • ¥30 在vs2022里运行python代码
  • ¥15 不同尺寸货物如何寻找合适的包装箱型谱
  • ¥15 求解 yolo算法问题
  • ¥15 虚拟机打包apk出现错误
  • ¥15 用visual studi code完成html页面
  • ¥15 聚类分析或者python进行数据分析
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备