I need a good php URL decoder for API testing

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>
<input type=text size=40 name=str value="<?=$str_s?>">
    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 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);
 
php/url_decoder.txt · Last modified: 2010/02/22 04:24 by muscardin
 
Except where otherwise noted, content on this wiki is licensed under the following license:CC Attribution-Noncommercial-Share Alike 3.0 Unported
Please visit Automatic Backlinks to start earning free backlinks Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki