I am trying to convert special characters (eg. +, /, &, %) which I will use them for a GET request. I have constructed a
+
/
&
%
Do not use a loop.
Use str_replace
str_replace($entities, $replacements, $string);
Or better use this native PHP function rawurlencode