According to https://stackoverflow.com/a/1734255/1529630, encodeURIComponent
is the same as rawurlencode
, but !*'()
aren't escaped, e.g.,
function encodeURIComponent($str) {
$revert = array('%21'=>'!', '%2A'=>'*', '%27'=>"'", '%28'=>'(', '%29'=>')');
return strtr(rawurlencode($str), $revert);
}
But then, does it matter that difference?
Normally, I use something like
- In JS
wrapper.innerHTML = '<a href="foo.php?bar=' + encodeURIComponent(myVar) + '">Link</a>';
- In PHP
echo '<a href="foo.php?bar=' . rawurlencode(myVar) . '">Link</a>';
If then, in foo.php
, I use $_GET['bar']
, is it possible to get different results, due to the difference between encodeURIComponent
and rawurlencode
?