We have a collection of built-in functions you can use in the Editor in combination with expression language.
Some are built-in functions imported from the PHP language, while others were created specifically for use in Editor. You can learn how to use functions in our Expression language guide.
PHP Functions
Note about the call_user_func() function:
PHP provides a vast number of functions, and we can’t register them all to be available in our expression language. However, if you need to use a PHP function (built-in or custom) that isn’t registered, you can use call_user_func()
to call any PHP function.
There is a small difference in our implementation of this function due to the use of the Symfony Expression Language. When passing arguments, you must pass them as an indexed array.
Here are a few examples:
${call_user_func('addslashes', ['some string'])}
${call_user_func('strcmp', ['Foo', 'Bar'])}
${call_user_func('time')}
String Manipulation:
-
strtolower
: Converts a string to lowercase. -
strtoupper
: Converts a string to uppercase. -
ucfirst
: Converts the first character of a string to uppercase. -
ucwords
: Uppercase the first character of each word in a string. -
strlen
: Returns the length of a string. -
str_replace
: Replaces all occurrences of the search string with the replacement string in a string. -
substr
: Returns a part of a string. -
stripos
: Returns the position of the first occurrence of a case-insensitive substring in a string. -
explode
: Splits a string by string and returns an array of substrings. -
implode
: Joins array elements with a string. -
trim
: Strips whitespace (or other characters) from the beginning and end of a string. -
preg_replace
: Performs a regular expression search and replace on a string. -
htmlentities
: Converts all applicable characters to HTML entities. -
htmlspecialchars
: Converts special characters to HTML entities. -
html_entity_decode
: Converts HTML entities to their corresponding characters. -
is_string
: Checks if the variable is a string. -
str_word_count
: Counts the number of words in a string.
Array Manipulation:
-
count
: Counts all elements in an array, or properties in an object. -
array_rand
: Picks one or more random keys out of an array. -
array_values
: Returns all the values of an array. -
array_splice
: Removes a portion of the array and replaces it with something else. -
is_array
: Finds whether a variable is an array. -
in_array
: Checks if a value exists in an array. -
array_search
: Searches the array for a given value and returns the corresponding key if successful. -
array_column
: Returns the values from a single column in the input array. -
array_keys
: Returns all the keys of an array. -
array_merge
: Combines one or more arrays into a single array. -
array_diff
: Computes the difference of arrays. -
array_filter
: Filters elements of an array using a callback function. -
unserialize
: Creates a PHP value from a stored representation. -
serialize
: Generates a storable representation of a value. -
array_slice
: Extracts a slice of an array. -
array_chunk
: Splits an array into chunks. -
is_countable
: Checks if the variable is countable. -
array_map
: Applies a callback function to the elements of the given arrays.
Numeric Operations:
-
is_numeric
: Finds whether a variable is a number or a numeric string. -
is_int
: Finds whether a variable is an integer. -
intval
: Returns the integer value of a variable. -
strval
: Returns the string value of a variable. -
ceil
: Rounds a number up to the nearest integer. -
floor
: Rounds a number down to the nearest integer. -
round
: Rounds a float. -
number_format
: Formats a number with grouped thousands. -
is_float
: Checks if the variable is a float. -
is_long
: Alias of is_int() – Checks if the variable is a long (integer).
Date and Time:
-
date
: Formats a local date and time. -
strtotime
: Parses an English textual datetime into a Unix timestamp. -
time
: Returns the current time as a Unix timestamp.
File Operations:
-
file_get_contents
: Reads entire file into a string. -
file_put_contents
: Write a string to a file. -
unlink
: Deletes a file.
JSON Manipulation:
-
json_last_error_msg
: Returns the error message of the last JSON encoding or decoding operation. -
json_last_error
: Returns the last error occurred during a JSON encoding or decoding operation. -
json_encode
: Returns the JSON representation of a value. -
json_decode
: Decodes a JSON string into a PHP value.
URL and Filtering:
-
urlencode
: URL-encodes a string. -
filter_var
: Filters a variable with a specified filter. -
parse_url
: Parses a URL and returns its components. -
rawurlencode
: Encodes a string according to RFC 3986. -
http_build_query
: Generate a URL-encoded query string from an associative array.
Miscellaneous:
-
rand
: Generates a random integer. -
is_object
: Finds whether a variable is an object. -
set_time_limit
: Sets the maximum execution time for a script. -
base64_encode
: Encodes data with MIME base64. -
hash_hmac
: Generate a keyed hash value using the HMAC method. -
uniqid
: Generate a unique ID. -
function_exists
: Return true if the given function has been defined. -
is_null
: Checks if the variable is NULL. -
constant
: Returns the value of a constant. -
sleep
: Delays the program execution for the specified number of seconds. -
usleep
: Delays the program execution for the specified number of microseconds.
Custom Functions
Array Functions:
Function Name | Description | Arguments | Return Type |
---|---|---|---|
array_shuffle |
Shuffles the elements of an array. | $array : The array to shuffle. |
Shuffled array, or the original value if not an array. |
array_push |
Appends an item to an array. | $array : The target array. $item : The item to append. |
Modified array, or the original value if not an array. |
array_sort_by_field |
Sorts an array based on a specified field. | $array : The target array. $field : The field to sort by. |
Sorted array, or the original value if not an array. |
human_concat |
Joins an array into a human-readable string, optionally using a specified conjunction for the last element. | $array : The target array. $conjunction (Optional): The conjunction to use for the last element. |
Human-readable string, or the original value if not an array. |
String Functions:
Function Name | Description | Arguments | Return Type |
---|---|---|---|
print_r |
Prints human-readable information about a variable. | $val : The variable to display. |
String representation of the variable. |
decode_special_chars |
Decodes special characters in a string. | $string : The string to decode. |
Decoded string, or the original value if not a string. |
ordinal |
Returns the ordinal representation of a number (e.g., 1st, 2nd, 3rd). | $string : Numeric string. |
Ordinal string, or the original value if not numeric. |
html_to_markdown |
Converts an HTML string to Markdown format. | $html : The HTML string to convert.$options (Optional): Array of options for conversion. |
Markdown formatted string. |
parse_cvs_file |
Parses a CSV file and returns its contents as a multidimensional array. | $path : The path to the CSV file. $separator (Optional): The separator character used in the CSV file. Default is comma (,). |
Multidimensional array containing the contents of the CSV file. |
General Functions:
Function Name | Description | Arguments | Return Type |
---|---|---|---|
empty |
Determines whether a variable is empty. | $var : The variable to check. |
Boolean (true if empty, false otherwise). |
call_user_func |
This function allows you to dynamically call a user-defined function with specified arguments. |
$callback : The function name as a string.$parameter (Optional): An indexed array of parameters to be passed to the function.
|
The return value of the called function. |
Date and Time Functions:
Function Name | Description | Arguments | Return Type |
---|---|---|---|
relative_date |
Returns a relative date string. | `$date`: The target date. `$startDayOfWeek` (Optional): Starting day of the week. |
Relative date string. |
date_tz |
Returns a formatted date string adjusted for a specified timezone. | `$format`: Date format. `$timestamp` (Optional): Target timestamp. `$timezone` (Optional): Target timezone. |
Formatted date string, or false on failure. |
strtotime_tz |
Converts a datetime string into a Unix timestamp, optionally adjusted for a timezone. | `$datetime`: Datetime string. `$baseTimestamp` (Optional): Base timestamp for relative datetime calculations. `$timezone` (Optional): Timezone for the datetime string. |
Unix timestamp. |
parse_date_time |
Parses a date-time string, potentially adjusting for platform-specific quirks. | `$date`: Date string. `$platform` (Optional): The platform string. Default is ‘amazon’. |
Parsed date-time string or false on failure. |
parse_duration |
Parses a duration string, potentially adjusting for platform-specific quirks and returning a default duration if none provided. | `$duration`: Duration string. `$platform` (Optional): The platform string. Default is ‘amazon’. `$defaultDuration` (Optional): Default duration to return if none provided. |
Parsed duration in seconds or the default duration. |