parsing – php parse string without decoding

parsing – php parse string without decoding

$route_var = $_REQUEST[route];
$pieces = explode(/, $route_var);
$sliced = array_slice($pieces, 3)
$based = implode(/, $sliced);
$pathslice = array_slice($pieces, 0,3);
$path = implode(/, $pathslice);
$b64part = urlencode($based);
$output = $path./.$b64part;

This should give you your correct encoded base64 if you echo output.

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
}

parsing – php parse string without decoding

Leave a Reply

Your email address will not be published. Required fields are marked *