note 86480 added to function.urlencode
| From: | jasen at free dot net dot nz | Date: | Tue, 21 Oct 2008 21:33:40 +0000 |
| Subject: | note 86480 added to function.urlencode | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-145547@lists.php.net to get a copy of this message | ||
I had need for a way to urlencode an array,
here's what I did.
the second (optional) parameter is for the variable name, it's mainly used for recursion over
arrays. you can ignore it and just use this instead of urlencode.
also included is the fix for # because sometimes I want to use # in a variable.
if you want to use the result it produces (normally you will) in HTML run it through
htmlspecialchars()
function urlcode($a,$wrap=''){
// like urlencode only better - it even does arrays!
if(!is_array($a))
{
if($wrap=='')return str_replace('#','%23',urlencode($a));
else return $wrap."=".str_replace('#','%23',urlencode($a));
}
$res='';
$amp='';
if($wrap=='')
foreach($a as $k => $v )
{
$res.=$amp.urlcode($v,urlcode($k));
$amp='&';
}
else
foreach($a as $k => $v )
{
$res.=$amp.urlcode($v,$wrap.'['.urlcode($k).']');
$amp='&';
}
return $res;
}
Does anyone know how to urlencode a resource ? :^)
----
Server IP: 202.89.58.1
Probable Submitter: 210.48.82.11
----
Manual Page -- http://www.php.net/manual/en/function.urlencode.php
Edit -- https://master.php.net/note/edit/86480
Del: integrated -- https://master.php.net/note/delete/86480/integrated
Del: useless -- https://master.php.net/note/delete/86480/useless
Del: bad code -- https://master.php.net/note/delete/86480/bad+code
Del: spam -- https://master.php.net/note/delete/86480/spam
Del: non-english -- https://master.php.net/note/delete/86480/non-english
Del: in docs -- https://master.php.net/note/delete/86480/in+docs
Del: other reasons-- https://master.php.net/note/delete/86480
Reject -- https://master.php.net/note/reject/86480
Search -- https://master.php.net/manage/user-notes.php