Description
The encodeURI function encodes a given string into a valid URI format. It replaces characters such as spaces, special characters, and umlauts so that the string can be safely used in a URL.
Syntax
encodeURI(string)
Arguments
| Argument | Description |
|---|---|
string |
The string to be encoded. This can be any text that needs to be adjusted for use in a URL. |
Return Types
The function returns the URI-encoded string. Special characters are converted into their respective encodings.
Examples
| Description | Formula | Result |
|---|---|---|
| Spaces in the string |
encodeURI("Hello World")
|
Hello%20World |
| Special characters |
encodeURI("A test@123")
|
A%20test%40123 |
| Umlauts and special characters |
encodeURI("Greetings & Fun")
|
Greetings%20%26%20Fun |
Notes
- The
encodeURIfunction is particularly useful for creating URLs that include user input or dynamic content. - It replaces certain characters but keeps reserved URL characters such as
:/and?unchanged.
Comments
0 comments
Please sign in to leave a comment.