How can I properly URL encode a string in PHP?

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 +) while rawurlencode encodes according to the plain Percent-Encoding (space is encoded with %20).

How to encode the plus (+) symbol in a URL

The + character has a special meaning in a URL => it means whitespace – . If you want to use the literal + sign, you need to URL encode it to %2b: body=Hi+there%2bHello+there Here’s an example of how you could properly generate URLs in .NET: var uriBuilder = new UriBuilder(“https://mail.google.com/mail”); var values = HttpUtility.ParseQueryString(string.Empty); … Read more

How do you UrlEncode without using System.Web?

System.Uri.EscapeUriString() can be problematic with certain characters, for me it was a number / pound ‘#’ sign in the string. If that is an issue for you, try: System.Uri.EscapeDataString() //Works excellent with individual values Here is a SO question answer that explains the difference: What’s the difference between EscapeUriString and EscapeDataString? and recommends to use … Read more

Should I URL-encode POST data?

General Answer The general answer to your question is that it depends. And you get to decide by specifying what your “Content-Type” is in the HTTP headers. A value of “application/x-www-form-urlencoded” means that your POST body will need to be URL encoded just like a GET parameter string. A value of “multipart/form-data” means that you’ll … Read more

Encoding URL query parameters in Java

java.net.URLEncoder.encode(String s, String encoding) can help too. It follows the HTML form encoding application/x-www-form-urlencoded. URLEncoder.encode(query, “UTF-8”); On the other hand, Percent-encoding (also known as URL encoding) encodes space with %20. Colon is a reserved character, so : will still remain a colon, after encoding.

Encode/Decode URLs in C++ [closed]

I faced the encoding half of this problem the other day. Unhappy with the available options, and after taking a look at this C sample code, i decided to roll my own C++ url-encode function: #include <cctype> #include <iomanip> #include <sstream> #include <string> using namespace std; string url_encode(const string &value) { ostringstream escaped; escaped.fill(‘0’); escaped … Read more