I need a good php URL decoder for API testing


Enter Your Query:
Use '%' for wildcards and quotes for "exact phrases"


Top Level » DirectAdmin » API and Plugins

I need a good php URL decoder for API testingLast Modified: Nov 29, 2019, 12:50 am
This is the php code that I use to test all new API output:

<html>
<head>
<title>url decode</title>
<style>
pre {
       margin: 0px;
}
div {
       border: 1px solid #d9d9d9;
}
</style>
</head>
<?php
$str_s='';
if (isset($_POST['str']))
       $str_s=$_POST['str'];

$sub_array = true;
if ($str_s!='' && !(isset($_POST['sub_array']) && $_POST['sub_array'] == 'yes'))
       $sub_array = false;
?>

<form action='?' method=POST>
<textarea name=str cols=120 rows=10><?php
       echo html_char($str_s);
?>
</textarea>

<input type=checkbox name='sub_array' value='yes' <?php if ($sub_array) echo 'checked';?>> Contains multi-level URL encoding<br>
<input type=submit>
</form><br><br>


<?php

show_enc($str_s);

function show_enc($str2, $tab=0)
{
       global $sub_array;

       $c = "style='margin-left: ".(($tab+1)*20)."px'";
       echo "<div $c>";

       parse_str($str2, $output);

       foreach ($output as $key => $value)
       {
               echo "<pre><b>".html_char(urldecode($key))."</b> = ";

               if ($sub_array && strpos($value, '=') !== false)
                       show_enc($value, $tab+1);
               else
                       echo html_char(urldecode($value));

               echo "</pre>";
       }
       echo "</div>\n";
}

function html_char($str)
{
       $h = htmlspecialchars(stripslashes($str), ENT_QUOTES | ENT_HTML401);
       if ($h == '' && $str != '')
               return htmlspecialchars(utf8_encode(stripslashes($str)), ENT_QUOTES | ENT_HTML401);
       else
               return $h;
}


?>
</html>


If you need to decode a list similar to:

list[]=value1&list[]=value2&list[]=value3&list[]=value4

then use something similar to this:

$str="list[]=value1&list[]=value2&list[]=value3&list[]=value4";
$a = explode('&', $str);
$values = Array();

$i=0;
foreach ($a as $v)
{
   $values[$i++] = substr(strstr($v, '='), 1);
}

print_r($values);

© 2018 JBMC Software, Suite 173  3-11 Bellerose Drive, St Albert, AB  T8N 1P7  Canada.  Mon-Fri 9AM-5PM MST