I’m having some trouble replacing the “+” sign with its urlencoded string of “%2B”. How can I do this?
This is what I’ve tried:
Text Entered into text box:
plus(+)
I then urlencode the string:
$string = urlencode($string);
String now looks like:
plus%28+%29
I want to have the “+” urlencoded, or else when I urldecode() the data to display in browser I end up with:
plus( )
because urldecode() interprets the “+” to be a space.
I tried using php’s str_replace() but I keep getting a “NULL” returned as the value for “$new_string”:
$new_string = str_replace('+', '%2B', $string);
Any ideas?
Thanks in advance!
That is strange. When I use
urlencodeonplus(+)I getplus%28%2B%29. Make sure you’re using it correctly.You might also try
rawurlencode. It will encode spaces as%20instead of+.