note 96394 added to function.urlencode
| From: | omid at omidsakhi dot com | Date: | Wed, 24 Feb 2010 19:17:50 +0000 |
| Subject: | note 96394 added to function.urlencode | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-166336@lists.php.net to get a copy of this message | ||
I needed a function in PHP to do the same job as the complete escape function in Javascript. It took
me some time not to find it. But findaly I decided to write my own code. So just to save time:
function fullescape($in)
{
$out = '';
for ($i=0;$i<strlen($in);$i++)
{
$hex = dechex(ord($in[$i]));
if ($hex=='')
$out = $out.urlencode($in[$i]);
else
$out = $out .'%'.((strlen($hex)==1) ?
('0'.strtoupper($hex)):(strtoupper($hex)));
}
$out = str_replace('+','%20',$out);
$out = str_replace('_','%5F',$out);
$out = str_replace('.','%2E',$out);
$out = str_replace('-','%2D',$out);
return $out;
}
It can be fully decoded using the unscape function in Javascript.
----
Server IP: 69.147.83.197
Probable Submitter: 93.10.198.33
----
Manual Page -- http://www.php.net/manual/en/function.urlencode.php
Edit -- https://master.php.net/note/edit/96394
Del: integrated -- https://master.php.net/note/delete/96394/integrated
Del: useless -- https://master.php.net/note/delete/96394/useless
Del: bad code -- https://master.php.net/note/delete/96394/bad+code
Del: spam -- https://master.php.net/note/delete/96394/spam
Del: non-english -- https://master.php.net/note/delete/96394/non-english
Del: in docs -- https://master.php.net/note/delete/96394/in+docs
Del: other reasons-- https://master.php.net/note/delete/96394
Reject -- https://master.php.net/note/reject/96394
Search -- https://master.php.net/manage/user-notes.php