I need a good php URL decoder for API testing


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


Top Level » DirectAdmin » DirectAdmin API and Plugins

I need a good php URL decoder for API testingLast Modified: Jul 4, 2013, 9:53 pm
This is the php code that I use to test all new API output:

<?
if (isset($_POST['str']))
{
        $str_s=$_POST['str'];
}
?>

<form action=? method=POST>
<textarea name=str><? echo $str_s; ?>
</textarea>
    Textarea:<input type=checkbox name=textarea value=yes>
<input type=submit>
</form><br><br>


<?

//$str2 = html_entity_decode($str_s);
$str2 = unhtmlentities($str_s);

echo $str2;
echo "<br><br>\n\n";

parse_str($str2, $output);

$ta = false;
if (isset($_POST['textarea']) && $_POST['textarea'] == "yes")
{
             $ta = true;
}

foreach ($output as $key = > $value)
{
            echo "<b>";
            echo urldecode($key);
            if ($ta) { echo "</b> = <textarea cols=120 rows=35 wrap=off>"; }
            else { echo "</b> = "; }

            echo htmlentities(urldecode($value));

            if ($ta) { echo "</textarea><br><br><br>\n\n\n"; }
            else { echo "<br><br><br>\n\n\n"; }
}

function unhtmlentities($string)
{
       return preg_replace('~&#([0-9][0-9])~e', 'chr(\\1)', $string);
}

?>


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);

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