I'm making a search page, where you type a search query and the form is submitted to search.php?query=your query
. What PHP function is the best and that I should use for encoding/decoding the search query?
For the URI query use urlencode
/urldecode
; for anything else use rawurlencode
/rawurldecode
.
The difference between urlencode
and rawurlencode
is that
urlencode
encodes according to application/x-www-form-urlencoded (space is encoded with +
) whilerawurlencode
encodes according to the plain Percent-Encoding (space is encoded with %20
).