Returns an url-encoded string with respect to charset.

urlEncode(string [, charset] [, force]) → returns string

Member Function Syntax

string.urlEncode([charset] [, force])

This function requires Lucee.  Not supported on Adobe ColdFusion, etc.

Argument Reference

string string

charset string
Default: utf-8

The character encoding in which the string will be encoded.
  • utf-8
  • iso-8859-1
  • windows-1252
  • us-ascii
  • shift_jis
  • iso-2022-jp
  • euc-jp
  • euc-kr
  • big5
  • euc-cn
  • utf-16

force boolean
Default: true

Sample code invoking the urlEncode function

Encode string with special chars for use in url

urlEncode('Apples → Äpfel','utf-8')

Expected Result: Apples+%E2%86%92+%C3%84pfel

Same string, different charset

urlEncode('Apples → Äpfel','ASCII')

Expected Result: Apples+%3F+%3Fpfel

vocab = [{
        apples: {
            en: 'apples',
            de: 'Äpfel',
            da: 'æble',
            el: 'μήλο'

Expected Result: %5B%7BAPPLES%3D%7B%7BEL%3D%7B%CE%BC%CE%AE%CE%BB%CE%BF%7D%2C+EN%3D%7Bapples%7D%2C+DA%3D%7B%C3%A6ble%7D%2C+DE%3D%7B%C3%84pfel%7D%7D%7D%7D%5D

Signup for cfbreak to stay updated on the latest news from the ColdFusion / CFML community. One email, every friday.

Fork me on GitHub