note 71142 added to function.rawurldecode
| From: | TomekPerlak | Date: | Mon, 13 Nov 2006 23:03:41 +0000 |
| Subject: | note 71142 added to function.rawurldecode | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-119693@lists.php.net to get a copy of this message | ||
Let's say you pass some data between the client and the server in a more or less array-like
structure.
If using the [] brackets in the field names is not enough (or won't comply with the rest of the
project for some reason), you might have to use a string with a number of different delimiters
(rows, fields, rows inside fields and such).
To make sure that the data doesn't get mistaken for delimiters, you can use the
encodeURIComponent() JavaScript function. It pairs nicely with rawurldecode().
Once the string passed to the server side finally gets exploded into an array (or set of such), you
could use the following function to recursively rawurldecode the array(s):
<?php
function rawurldecode_array(&$arr)
{
foreach (array_keys($arr) as $key)
{
if (is_array($arr[$key]))
{
rawurldecode_array($arr[$key]);
}
else
{
$arr[$key] = rawurldecode($arr[$key]);
}
}
}
$a[0] = rawurlencode("2+1:3?9");
$a["k"] = rawurlencode("@:-/");
$a[-3][0] = rawurlencode("+");
$a[-3][2] = rawurlencode("=_~");
$a[-3]["a"] = rawurlencode("this+is a%test");
echo "<pre>"; print_r($a); echo "</pre>";
rawurldecode_array($a);
echo "<pre>"; print_r($a); echo "</pre>";
?>
The program will output:
Array
(
[0] => 2%2B1%3A3%3F9
[k] => %40%3A-%2F
[-3] => Array
(
[0] => %2B
[2] => %3D_%7E
[a] => this%2Bis%20a%25test
)
)
Array
(
[0] => 2+1:3?9
[k] => @:-/
[-3] => Array
(
[0] => +
[2] => =_~
[a] => this+is a%test
)
)
----
Server IP: 66.163.161.117
Probable Submitter: 146.145.79.123
----
Manual Page -- http://www.php.net/manual/en/function.rawurldecode.php
Edit -- https://master.php.net/note/edit/71142
Del: integrated -- https://master.php.net/note/delete/71142/integrated
Del: useless -- https://master.php.net/note/delete/71142/useless
Del: bad code -- https://master.php.net/note/delete/71142/bad+code
Del: spam -- https://master.php.net/note/delete/71142/spam
Del: non-english -- https://master.php.net/note/delete/71142/non-english
Del: in docs -- https://master.php.net/note/delete/71142/in+docs
Del: other reasons-- https://master.php.net/note/delete/71142
Reject -- https://master.php.net/note/reject/71142
Search -- https://master.php.net/manage/user-notes.php