
342 views
HTML URL Encode
HTML URL encoding is a method of encoding special characters in a URL to ensure that the URL is properly formatted and can be transmitted correctly over the internet. URL encoding replaces certain characters with a percent sign (%) followed by a two-digit hexadecimal value that represents the character code.
Here are some common HTML URL-encoded characters:
- Space – %20
- ! – %21
- ” – %22
- – %23
- $ – %24
- % – %25
- & – %26
- ‘ – %27
- ( – %28
- ) – %29
To URL-encode a string of text, you can use a variety of online encoding tools or JavaScript functions, such as encodeURIComponent()
. Here’s an example of how to encode a string using JavaScript:
var myString = "Hello, world!";
var encodedString = encodeURIComponent(myString);
console.log(encodedString); // Output: "Hello%2C%20world%21"
In this example, the encodeURIComponent()
function encodes the string “Hello, world!” as “Hello%2C%20world%21”, which can be used as part of a URL.