note 47591 deleted from function.urlencode by sean
| From: | sean@php.net | Date: | Mon, 22 Nov 2004 15:16:52 +0000 |
| Subject: | note 47591 deleted from function.urlencode by sean | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-80871@lists.php.net to get a copy of this message | ||
Note Submitter: wesam23 at yahoo dot com
----
I have problem when using special charactes e.g. $,#, etc when redirecting in link with GET
variable.
for a variable that will hold "me & friend". it will cause misinterpreting when using
GET method:
<?
$val="me & friend";
?>
<a href="test.php?info=<?=$val?>">Click here</a>
you will not get the expected value in test.php, to solve this I suggested the following function
which will encode the variable to make it suitable for GET method.
function encodeURLx($instr)
{
for($i=0;$i<strlen($instr);$i++)
{
$ch=substr($instr,$i,1);
switch($ch)
{
case chr(9):
case chr(32):
case chr(34):
case chr(44):
case chr(40):
case chr(41):
case chr(58):
case chr(59):
case chr(60):
case chr(62):
case chr(64):
case chr(124):
case chr(47):
case chr(92):
case chr(35):
case chr(37):
case chr(38):
case chr(43):
case chr(61):
case chr(63):
$hx= "%" . sprintf("%0x",ord($ch));
$tmp.=$hx;
break;
default:
$tmp.=$ch;
}
}
return $tmp;
}
$val=encodeURLx($val);
----
Reason: useless example