Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
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

 Answers
22

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, - _ . ! ~ * ' ( )



[#98314] Tuesday, November 10, 2009, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
emerymariamm

Total Points: 276
Total Questions: 97
Total Answers: 99

Location: Comoros
Member since Sun, Dec 13, 2020
4 Years ago
;