URLEncoder()

Syntax

Result$ = URLEncoder(URL$ [, Format])
Description
Returns the URL$ encoded to the HTTP format.

Parameters

URL$ The URL to encode.
Format (optional) The format of the string before encoding it. It can be one of the following values:
  #PB_UTF8  (default)
  #PB_Ascii

Return value

Returns the encoded URL. To convert an encoded URL back to a unencoded format, use URLDecoder()

Remarks

A URL$ may not contain certain characters such as: tab, space, accent letter etc., therefore these characters must be encoded, which basically involves using "%" as an escape character.

Because this function use the RFC 3986 standard, some characters will not be encoded, such as (non-exhaustive list):
  "-" | "_" | "." | "!" | "~" | "*" | "'" | "(" | ")" | 
  ";" | "/" | "?" | ":" | "@" | "&" | "=" | "+" | "$" |
  "," | """ | "#" | "%" | 
Anyway, if you need to encode them, you will need to use the following table: https://www.w3schools.com/tags/ref_urlencode.asp

For example in UTF8:
   "-" -> %2D | "_" -> %5F | "." -> %2E | "!" -> %21 | "~" -> %7E | 
   
   "*" -> %2A | "'" -> %27 | "(" -> %28 | ")" -> %29 | ";" -> %3B | 
   
   "/" -> %2F | "?" -> %3F | ":" -> %3A | "@" -> %40 | "&" -> %26 | 
   
   "=" -> %3D | "+" -> %2B | "$" -> %24 | "," -> %2C | """ -> %22 | 
   
   "#" -> %23 | "%" -> %25 |  

Example

  Debug URLEncoder("http://www.purebasic.com/test with space.php3")
  ; Will print "http://www.purebasic.com/test%20with%20space.php3"
  
  Debug URLEncoder("http://www.ok.com value=zzz ?yyy/")
  ; Will print "http://www.ok.com%20value=zzz%20?yyy/"

See Also

URLDecoder()

Supported OS

All

<- URLDecoder() - Http Index