177
rated 0 times
[
182]
[
5]
/ answers: 1 / hits: 75686
/ 15 Years ago, sat, november 14, 2009, 12:00:00
What is the equivalent of JavaScript's encodeURIcomponent
function in PHP?
More From » php
What is the equivalent of JavaScript's encodeURIcomponent
function in PHP?
Try rawurlencode
. Or to be more precise:
function encodeURIComponent($str) {
$revert = array('%21'=>'!', '%2A'=>'*', '%27'=>', '%28'=>'(', '%29'=>')');
return strtr(rawurlencode($str), $revert);
}
This function works exactly how encodeURIComponent
is defined:
encodeURIComponent
escapes all characters except the following: alphabetic, decimal digits,-
_
.
!
~
*
'
(
)