How to properly URL encode a string in PHP?

Click Upvote picture Click Upvote · Jan 20, 2011 · Viewed 222k times · Source

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?

Answer

Gumbo picture Gumbo · Jan 20, 2011

For the URI query use urlencode/urldecode; for anything else use rawurlencode/rawurldecode.

The difference between urlencode and rawurlencode is that