%20
vs. +
The biggest reason I've seen to use rawurlencode()
in most cases is because urlencode
encodes text spaces as +
(plus signs) where rawurlencode
encodes them as the commonly-seen %20
:
echo urlencode("red shirt");
// red+shirt
echo rawurlencode("red shirt");
// red%20shirt
I have specifically seen certain API endpoints that accept encoded text queries expect to see %20
for a space and as a result, fail if a plus sign is used instead. Obviously this is going to differ between API implementations and your mileage may vary.