Oihana PHP Arango

strings

Table of Contents

Functions

charLength()  : string
Return the number of characters in a string (not byte length).
concat()  : string
Concatenate multiple values into a single string.
concatSeparator()  : string
Concatenate strings using a separator.
contains()  : string
Check whether a string contains a substring (case-sensitive).
crc32()  : string
Calculate the CRC32 checksum for text and return it in hexadecimal format.
encodeURIComponent()  : string
Return the URI component-encoded string of a value.
findFirst()  : string
Return the position of the first occurrence of a substring in a string.
findLast()  : string
Return the position of the last occurrence of a substring in a string.
fnv64()  : string
Calculate the FNV-1A 64-bit hash for text and return it in hexadecimal format.
ipv4FromNumber()  : string
Convert a numeric IPv4 address value into its string representation.
ipv4ToNumber()  : string
Convert an IPv4 address string into its numeric representation.
isIPV4()  : string
Check if an arbitrary string is suitable for interpretation as an IPv4 address.
jsonParse()  : string
Return an AQL value described by the JSON-encoded input string.
jsonStringify()  : string
Return a JSON string representation of the input value.
left()  : string
Return the leftmost characters of a string.
levenshtein()  : string
Calculate the Damerau-Levenshtein distance between two strings.
like()  : string
Check whether a pattern matches a string using wildcard matching.
lower()  : string
Convert uppercase letters to lowercase.
ltrim()  : string
Remove whitespace from the start of a string.
md5()  : string
Calculate the MD5 checksum for text and return it in hexadecimal format.
randomToken()  : string
Generate a pseudo-random token string with the specified length.
right()  : string
Return the rightmost characters of a string.
rtrim()  : string
Remove whitespace from the end of a string.
sha1()  : string
Calculate the SHA1 checksum for text and return it in hexadecimal format.
sha256()  : string
Calculate the SHA256 checksum for text and return it in hexadecimal format.
sha512()  : string
Calculate the SHA512 checksum for text and return it in hexadecimal format.
soundex()  : string
Return the Soundex fingerprint of a value.
split()  : string
Split a string into an array using a separator.
startsWith()  : string
Check whether a string starts with a prefix (or with one of several prefixes).
subString()  : string
Return a substring of a string.
toBase64()  : string
Return the Base64 representation of a value.
toChar()  : string
Return the character with the specified Unicode codepoint.
toHex()  : string
Return the hexadecimal representation of a value.
tokens()  : string
Split input string(s) using the specified analyzer into an array of tokens.
trim()  : string
Removes whitespace or specific characters from the start and/or end of a string.
upper()  : string
Convert lowercase letters to uppercase.
uuid()  : string
Return a universally unique identifier (UUID).

Functions

charLength()

Return the number of characters in a string (not byte length).

charLength(string $expression) : string

This helper wraps the ArangoDB AQL function CHAR_LENGTH(str) which returns the number of characters in a string, counting Unicode characters properly rather than bytes.

Example AQL usage:

CHAR_LENGTH("hello")          // returns 5
CHAR_LENGTH("café")           // returns 4 (not 5 bytes)
CHAR_LENGTH(doc.title)        // returns character count of title
Parameters
$expression : string

String expression to count characters of.

Tags
example
use function oihana\arango\db\functions\strings\charLength;

$expr = charLength('doc.title');
// Produces: 'CHAR_LENGTH(doc.title)'
see
https://docs.arangodb.com/stable/aql/functions/string/#char_length
since
1.0.0
author

Marc Alcaraz

Return values
string

The formatted AQL expression.

concat()

Concatenate multiple values into a single string.

concat(array<string|int, mixed>|string|null $arguments) : string

This helper wraps the ArangoDB AQL function CONCAT(value1, value2, ... valueN) which concatenates multiple values into a single string. Values are automatically converted to strings during concatenation.

Example AQL usage:

CONCAT("Hello", " ", "World")     // returns "Hello World"
CONCAT(doc.firstName, " ", doc.lastName)  // concatenates name parts
CONCAT("ID: ", doc._key)          // returns "ID: 123"
Parameters
$arguments : array<string|int, mixed>|string|null

An AQL string expression or an array of AQL values.

Tags
example
use function oihana\arango\db\functions\strings\concat;

$expr = concat(['"Hello"', '" "', '"World"']);
// Produces: 'CONCAT("Hello", " ", "World")'

$expr = concat('doc.firstName, " ", doc.lastName');
// Produces: 'CONCAT(doc.firstName, " ", doc.lastName)'
throws
UnsupportedOperationException
see
https://docs.arangodb.com/stable/aql/functions/string/#concat
concatSeparator()

For concatenating with a separator.

since
1.0.0
author

Marc Alcaraz

Return values
string

The formatted AQL expression.

concatSeparator()

Concatenate strings using a separator.

concatSeparator([string $separator = Char::EMPTY ][, array<string|int, mixed>|string|null $arguments = null ]) : string

This helper wraps the ArangoDB AQL function CONCAT_SEPARATOR(separator, value1, value2, ... valueN) which concatenates multiple values into a single string using the specified separator between each value.

Example AQL usage:

CONCAT_SEPARATOR(", ", "a", "b", "c")     // returns "a, b, c"
CONCAT_SEPARATOR(" - ", doc.first, doc.last)  // returns "John - Doe"
CONCAT_SEPARATOR("", "a", "b", "c")       // returns "abc" (no separator)
Parameters
$separator : string = Char::EMPTY

The separator string to use between values.

$arguments : array<string|int, mixed>|string|null = null

An AQL string expression or an array of AQL values.

Tags
throws
UnsupportedOperationException
example
use function oihana\arango\db\functions\strings\concatSeparator;

$expr = concatSeparator('", "', ['"a"', '"b"', '"c"']);
// Produces: 'CONCAT_SEPARATOR(", ", "a", "b", "c")'
see
https://docs.arangodb.com/stable/aql/functions/string/#concat_separator
concat()

For concatenating without a separator.

since
1.0.0
author

Marc Alcaraz

Return values
string

The formatted AQL expression.

contains()

Check whether a string contains a substring (case-sensitive).

contains(string $text, string $search[, bool $returnIndex = false ]) : string

This helper wraps the ArangoDB AQL function CONTAINS(text, search, returnIndex) which checks if the search string is contained within the text string. The matching is case-sensitive by default.

Example AQL usage:

CONTAINS("Hello World", "World")        // returns true
CONTAINS("Hello World", "world")        // returns false (case-sensitive)
CONTAINS("Hello World", "World", true)  // returns 6 (position)
Parameters
$text : string

The text to search in.

$search : string

The substring to search for.

$returnIndex : bool = false

When true, returns the position; when false, returns boolean.

Tags
throws
UnsupportedOperationException
example
use function oihana\arango\db\functions\strings\contains;

$expr = contains('doc.title', '"World"');
// Produces: 'CONTAINS(doc.title, "World")'

$expr = contains('doc.title', '"World"', true);
// Produces: 'CONTAINS(doc.title, "World", true)'
see
https://docs.arangodb.com/stable/aql/functions/string/#contains
since
1.0.0
author

Marc Alcaraz

Return values
string

The formatted AQL expression.

crc32()

Calculate the CRC32 checksum for text and return it in hexadecimal format.

crc32(string $value) : string

This helper wraps the ArangoDB AQL function CRC32(text) which calculates the CRC32 checksum for the given text and returns it as a hexadecimal string. The polynomial used is 0x1EDC6F41 with initial value 0xFFFFFFFF and final XOR 0xFFFFFFFF.

Example AQL usage:

CRC32("hello")                // returns "3610a686"
CRC32("world")                // returns "4a17b156"
CRC32(doc.content)            // returns CRC32 checksum of content
Parameters
$value : string

String expression to calculate CRC32 checksum for.

Tags
example
use function oihana\arango\db\functions\strings\crc32;

$expr = crc32('doc.content');
// Produces: 'CRC32(doc.content)'
see
https://docs.arangodb.com/stable/aql/functions/string/#crc32
md5()

For MD5 hash.

sha1()

For SHA1 hash.

since
1.0.0
author

Marc Alcaraz

Return values
string

The formatted AQL expression.

encodeURIComponent()

Return the URI component-encoded string of a value.

encodeURIComponent(string $value) : string

This helper wraps the ArangoDB AQL function ENCODE_URI_COMPONENT(value) which returns the URI component-encoded version of the input string. This is useful for encoding special characters in URL components.

Example AQL usage:

ENCODE_URI_COMPONENT("hello world")       // returns "hello%20world"
ENCODE_URI_COMPONENT("a+b=c")             // returns "a%2Bb%3Dc"
ENCODE_URI_COMPONENT(doc.name)            // returns encoded name
Parameters
$value : string

String expression to encode.

Tags
example
use function oihana\arango\db\functions\strings\encodeURIComponent;

$expr = encodeURIComponent('doc.name');
// Produces: 'ENCODE_URI_COMPONENT(doc.name)'
see
https://docs.arangodb.com/stable/aql/functions/string/#encode_uri_component
since
1.0.0
author

Marc Alcaraz

Return values
string

The formatted AQL expression.

findFirst()

Return the position of the first occurrence of a substring in a string.

findFirst(string $value, string $search, int|null $start, int|null $end) : string

This helper wraps the ArangoDB AQL function FIND_FIRST(text, search, start, end) which returns the position of the first occurrence of the search string within the text string. Positions start at 0. You can optionally limit the search to a subset of the text using start and end parameters.

Example AQL usage:

FIND_FIRST("hello world", "world")        // returns 6
FIND_FIRST("hello world", "o")            // returns 4
FIND_FIRST("hello world", "x")            // returns -1 (not found)
FIND_FIRST("hello world", "o", 5)         // returns 7 (search from position 5)
Parameters
$value : string

The text to search in (haystack).

$search : string

The substring to search for (needle).

$start : int|null

Optional start position to limit search (default: 0).

$end : int|null

Optional end position to limit search (default: end of string).

Tags
example
use function oihana\arango\db\functions\strings\findFirst;

$expr = findFirst('doc.text', '"world"', 0, null);
// Produces: 'FIND_FIRST(doc.text, "world", 0)'
see
https://docs.arangodb.com/stable/aql/functions/string/#find_first
findLast()

For finding the last occurrence.

contains()

For checking if string contains substring.

since
1.0.0
author

Marc Alcaraz

Return values
string

The formatted AQL expression.

findLast()

Return the position of the last occurrence of a substring in a string.

findLast(string $value, string $search, int|null $start, int|null $end) : string

This helper wraps the ArangoDB AQL function FIND_LAST(text, search, start, end) which returns the position of the last occurrence of the search string within the text string. Positions start at 0. You can optionally limit the search to a subset of the text using start and end parameters.

Example AQL usage:

FIND_LAST("hello world", "o")             // returns 7
FIND_LAST("hello world", "l")             // returns 9
FIND_LAST("hello world", "x")             // returns -1 (not found)
FIND_LAST("hello world", "o", 0, 5)       // returns 4 (search in first 5 chars)
Parameters
$value : string

The text to search in (haystack).

$search : string

The substring to search for (needle).

$start : int|null

Optional start position to limit search (default: 0).

$end : int|null

Optional end position to limit search (default: end of string).

Tags
example
use function oihana\arango\db\functions\strings\findLast;

$expr = findLast('doc.text', '"o"', 0, null);
// Produces: 'FIND_LAST(doc.text, "o", 0)'
see
https://docs.arangodb.com/stable/aql/functions/string/#find_last
findFirst()

For finding the first occurrence.

contains()

For checking if string contains substring.

since
1.0.0
author

Marc Alcaraz

Return values
string

The formatted AQL expression.

fnv64()

Calculate the FNV-1A 64-bit hash for text and return it in hexadecimal format.

fnv64(string $value) : string

This helper wraps the ArangoDB AQL function FNV64(text) which calculates the FNV-1A 64-bit hash for the given text and returns it as a hexadecimal string. FNV (Fowler-Noll-Vo) is a fast, non-cryptographic hash function.

Example AQL usage:

FNV64("hello")                // returns "a430d84680aabd0b"
FNV64("world")                // returns "a430d84680aabd0b"
FNV64(doc.content)            // returns FNV64 hash of content
Parameters
$value : string

String expression to calculate FNV64 hash for.

Tags
example
use function oihana\arango\db\functions\strings\fnv64;

$expr = fnv64('doc.content');
// Produces: 'FNV64(doc.content)'
see
https://docs.arangodb.com/stable/aql/functions/string/#fnv64
md5()

For MD5 hash.

sha1()

For SHA1 hash.

crc32()

For CRC32 checksum.

since
1.0.0
author

Marc Alcaraz

Return values
string

The formatted AQL expression.

ipv4FromNumber()

Convert a numeric IPv4 address value into its string representation.

ipv4FromNumber(string $value) : string

This helper wraps the ArangoDB AQL function IPV4_FROM_NUMBER(numericAddress) which converts a numeric IPv4 address (32-bit integer) into its dotted decimal string representation.

Example AQL usage:

IPV4_FROM_NUMBER(2130706433)  // returns "127.0.0.1"
IPV4_FROM_NUMBER(3232235521)  // returns "192.168.0.1"
IPV4_FROM_NUMBER(0)           // returns "0.0.0.0"
IPV4_FROM_NUMBER(4294967295)  // returns "255.255.255.255"
Parameters
$value : string

Numeric IPv4 address expression to convert.

Tags
example
use function oihana\arango\db\functions\strings\ipv4FromNumber;

$expr = ipv4FromNumber('doc.ipNumber');
// Produces: 'IPV4_FROM_NUMBER(doc.ipNumber)'
see
https://docs.arangodb.com/stable/aql/functions/string/#ipv4_from_number
ipv4ToNumber()

For converting string to numeric IPv4.

isIPV4()

For validating IPv4 addresses.

since
1.0.0
author

Marc Alcaraz

Return values
string

The formatted AQL expression.

ipv4ToNumber()

Convert an IPv4 address string into its numeric representation.

ipv4ToNumber(string $value) : string

This helper wraps the ArangoDB AQL function IPV4_TO_NUMBER(stringAddress) which converts an IPv4 address in dotted decimal notation into its 32-bit numeric representation.

Example AQL usage:

IPV4_TO_NUMBER("127.0.0.1")   // returns 2130706433
IPV4_TO_NUMBER("192.168.0.1") // returns 3232235521
IPV4_TO_NUMBER("0.0.0.0")     // returns 0
IPV4_TO_NUMBER("255.255.255.255") // returns 4294967295
Parameters
$value : string

IPv4 address string expression to convert.

Tags
example
use function oihana\arango\db\functions\strings\ipv4ToNumber;

$expr = ipv4ToNumber('doc.ipAddress');
// Produces: 'IPV4_TO_NUMBER(doc.ipAddress)'
see
https://docs.arangodb.com/stable/aql/functions/string/#ipv4_to_number
ipv4FromNumber()

For converting numeric to string IPv4.

isIPV4()

For validating IPv4 addresses.

since
1.0.0
author

Marc Alcaraz

Return values
string

The formatted AQL expression.

isIPV4()

Check if an arbitrary string is suitable for interpretation as an IPv4 address.

isIPV4(string $value) : string

This helper wraps the ArangoDB AQL function IS_IPV4(value) which checks whether the given string is a valid IPv4 address in dotted decimal notation.

Example AQL usage:

IS_IPV4("127.0.0.1")         // returns true
IS_IPV4("192.168.0.1")       // returns true
IS_IPV4("256.0.0.1")         // returns false (invalid octet)
IS_IPV4("not an ip")         // returns false
Parameters
$value : string

String expression to validate as IPv4 address.

Tags
example
use function oihana\arango\db\functions\strings\isIPV4;

$expr = isIPV4('doc.ipAddress');
// Produces: 'IS_IPV4(doc.ipAddress)'
see
https://docs.arangodb.com/stable/aql/functions/string/#is_ipv4
ipv4FromNumber()

For converting numeric to string IPv4.

ipv4ToNumber()

For converting string to numeric IPv4.

since
1.0.0
author

Marc Alcaraz

Return values
string

The formatted AQL expression.

jsonParse()

Return an AQL value described by the JSON-encoded input string.

jsonParse(string $text) : string

This helper wraps the ArangoDB AQL function JSON_PARSE(text) which parses a JSON string and returns the corresponding AQL value. This is useful for converting JSON strings back into native AQL data types.

Example AQL usage:

JSON_PARSE('{"name": "John"}')    // returns {name: "John"}
JSON_PARSE('[1, 2, 3]')          // returns [1, 2, 3]
JSON_PARSE('"hello"')            // returns "hello"
JSON_PARSE('true')               // returns true
Parameters
$text : string

JSON string expression to parse.

Tags
example
use function oihana\arango\db\functions\strings\jsonParse;

$expr = jsonParse('doc.jsonString');
// Produces: 'JSON_PARSE(doc.jsonString)'
see
https://docs.arangodb.com/stable/aql/functions/string/#json_parse
jsonStringify()

For converting AQL values to JSON strings.

since
1.0.0
author

Marc Alcaraz

Return values
string

The formatted AQL expression.

jsonStringify()

Return a JSON string representation of the input value.

jsonStringify(mixed $value) : string

This helper wraps the ArangoDB AQL function JSON_STRINGIFY(value) which converts an AQL value into its JSON string representation. This is useful for serializing AQL data types to JSON format.

Example AQL usage:

JSON_STRINGIFY({name: "John"})    // returns '{"name":"John"}'
JSON_STRINGIFY([1, 2, 3])         // returns '[1,2,3]'
JSON_STRINGIFY("hello")           // returns '"hello"'
JSON_STRINGIFY(true)              // returns 'true'
Parameters
$value : mixed

AQL value expression to convert to JSON string.

Tags
example
use function oihana\arango\db\functions\strings\jsonStringify;

$expr = jsonStringify('doc.data');
// Produces: 'JSON_STRINGIFY(doc.data)'
see
https://docs.arangodb.com/stable/aql/functions/string/#json_stringify
jsonParse()

For parsing JSON strings back to AQL values.

since
1.0.0
author

Marc Alcaraz

Return values
string

The formatted AQL expression.

left()

Return the leftmost characters of a string.

left(string $value, int $length) : string

This helper wraps the ArangoDB AQL function LEFT(value, length) which returns the specified number of characters from the left (beginning) of the string.

Example AQL usage:

LEFT("hello world", 5)        // returns "hello"
LEFT("hello world", 0)        // returns ""
LEFT("hello world", 20)       // returns "hello world" (entire string)
LEFT(doc.title, 10)           // returns first 10 characters of title
Parameters
$value : string

String expression to extract characters from.

$length : int

Number of characters to return from the left.

Tags
example
use function oihana\arango\db\functions\strings\left;

$expr = left('doc.title', 10);
// Produces: 'LEFT(doc.title, 10)'
see
https://docs.arangodb.com/stable/aql/functions/string/#left
right()

For extracting characters from the right.

subString()

For extracting characters from any position.

since
1.0.0
author

Marc Alcaraz

Return values
string

The formatted AQL expression.

levenshtein()

Calculate the Damerau-Levenshtein distance between two strings.

levenshtein(string $value1, string $value2) : string

This helper wraps the ArangoDB AQL function LEVENSHTEIN_DISTANCE(value1, value2) which calculates the Damerau-Levenshtein distance between two strings. This distance represents the minimum number of operations (insertions, deletions, substitutions, and transpositions) needed to transform one string into another.

Example AQL usage:

LEVENSHTEIN_DISTANCE( "kitten" , "sitting" ) // returns 3
LEVENSHTEIN_DISTANCE( "hello"  , "hello"   ) // returns 0 (identical)
LEVENSHTEIN_DISTANCE( ""       , "hello"   ) // returns 5 (all insertions)
LEVENSHTEIN_DISTANCE( "abc"    , "bac"     ) // returns 1 (one transposition)
Parameters
$value1 : string

First string expression.

$value2 : string

Second string expression.

Tags
example
use function oihana\arango\db\functions\strings\levenshtein;

$expr = levenshtein('doc.name1', 'doc.name2');
// Produces: 'LEVENSHTEIN_DISTANCE(doc.name1, doc.name2)'
see
https://docs.arangodb.com/stable/aql/functions/string/#levenshtein_distance
https://en.wikipedia.org/wiki/Damerau%E2%80%93Levenshtein_distance
since
1.0.0
author

Marc Alcaraz

Return values
string

The formatted AQL expression.

like()

Check whether a pattern matches a string using wildcard matching.

like(string $text, string $search[, bool $caseInsensitive = false ]) : string

This helper wraps the ArangoDB AQL function LIKE(text, search, caseInsensitive) which checks if the text matches the search pattern using wildcard characters. The pattern supports wildcards: _ (single character) and % (multiple characters).

Example AQL usage:

LIKE("hello", "h%")           // returns true
LIKE("hello", "h_llo")        // returns true
LIKE("hello", "world")        // returns false
LIKE("Hello", "h%", true)     // returns true (case-insensitive)
LIKE("hello", "\\_")          // returns false (literal underscore)
Parameters
$text : string

The text to search in.

$search : string

The search pattern with wildcards (_ and %).

$caseInsensitive : bool = false

When true, matching is case-insensitive (maps to AQL's third caseInsensitive argument). Default false = case-sensitive.

Tags
example
use function oihana\arango\db\functions\strings\like;

echo like('doc.name', '"John%"');        // LIKE(doc.name,"John%")        case-sensitive
echo like('doc.name', '"john%"', true);  // LIKE(doc.name,"john%",true)   case-insensitive
see
https://docs.arangodb.com/stable/aql/functions/string/#like
contains()

For simple substring matching.

since
1.0.0
author

Marc Alcaraz

Return values
string

The formatted AQL expression.

lower()

Convert uppercase letters to lowercase.

lower(string $value) : string

This helper wraps the ArangoDB AQL function LOWER(value) which converts all uppercase letters in a string to their lowercase counterparts while leaving all other characters unchanged.

Example AQL usage:

LOWER("Hello World")           // returns "hello world"
LOWER("123 ABC")               // returns "123 abc"
LOWER(doc.title)               // converts title to lowercase
Parameters
$value : string

String expression to convert to lowercase.

Tags
example
use function oihana\arango\db\functions\strings\lower;

$expr = lower('doc.title');
// Produces: 'LOWER(doc.title)'
see
https://docs.arangodb.com/stable/aql/functions/string/#lower
upper()

For converting to uppercase.

since
1.0.0
author

Marc Alcaraz

Return values
string

The formatted AQL expression.

ltrim()

Remove whitespace from the start of a string.

ltrim(string $value[, string|null $chars = null ]) : string

This helper wraps the ArangoDB AQL function LTRIM(value, chars) which removes whitespace characters from the beginning (left side) of a string. You can specify custom characters to remove instead of the default whitespace.

Example AQL usage:

LTRIM("  hello world  ")      // returns "hello world  "
LTRIM("***hello***", "*")     // returns "hello***"
LTRIM("  hello")              // returns "hello"
LTRIM(doc.title)              // removes leading whitespace from title
Parameters
$value : string

String expression to trim from the left.

$chars : string|null = null

Optional characters to remove (defaults to whitespace).

Tags
example
use function oihana\arango\db\functions\strings\ltrim;

$expr = ltrim('doc.title');
// Produces: 'LTRIM(doc.title)'

$expr = ltrim('doc.title', '"*"');
// Produces: 'LTRIM(doc.title, "*")'
see
https://docs.arangodb.com/stable/aql/functions/string/#ltrim
rtrim()

For trimming from the right.

trim()

For trimming from both sides.

since
1.0.0
author

Marc Alcaraz

Return values
string

The formatted AQL expression.

md5()

Calculate the MD5 checksum for text and return it in hexadecimal format.

md5(string $value) : string

This helper wraps the ArangoDB AQL function MD5(text) which calculates the MD5 checksum for the given text and returns it as a hexadecimal string. MD5 is a widely used cryptographic hash function producing a 128-bit hash.

Example AQL usage:

MD5("hello")     // returns "5d41402abc4b2a76b9719d911017c592"
MD5("world")     // returns "7d865e959b2466918c9863afca942d0fb"
MD5(doc.content) // returns MD5 hash of content
Parameters
$value : string

String expression to calculate MD5 hash for.

Tags
example
use function oihana\arango\db\functions\strings\md5;

$expr = md5('doc.content');
// Produces: 'MD5(doc.content)'
see
https://docs.arangodb.com/stable/aql/functions/string/#md5
sha1()

For SHA1 hash.

sha256()

For SHA256 hash.

crc32()

For CRC32 checksum.

since
1.0.0
author

Marc Alcaraz

Return values
string

The formatted AQL expression.

randomToken()

Generate a pseudo-random token string with the specified length.

randomToken(int $length) : string

This helper wraps the ArangoDB AQL function RANDOM_TOKEN(length) which generates a pseudo-random token string. The algorithm for token generation should be treated as opaque. The length must be between 0 and 65536.

Example AQL usage:

RANDOM_TOKEN(8)               // returns a random 8-character string
RANDOM_TOKEN(16)              // returns a random 16-character string
RANDOM_TOKEN(0)               // returns "" (empty string)
RANDOM_TOKEN(32)              // returns a random 32-character string
Parameters
$length : int

Desired string length for the token (0-65536).

Tags
example
use function oihana\arango\db\functions\strings\randomToken;

$expr = randomToken(16);
// Produces: 'RANDOM_TOKEN(16)'
see
https://docs.arangodb.com/stable/aql/functions/string/#random_token
uuid()

For generating UUIDs.

since
1.0.0
author

Marc Alcaraz

Return values
string

The formatted AQL expression.

right()

Return the rightmost characters of a string.

right(string $value, int $length) : string

This helper wraps the ArangoDB AQL function RIGHT(value, length) which returns the specified number of characters from the right (end) of the string.

Example AQL usage:

RIGHT("hello world", 5)       // returns "world"
RIGHT("hello world", 0)       // returns ""
RIGHT("hello world", 20)      // returns "hello world" (entire string)
RIGHT(doc.title, 10)          // returns last 10 characters of title
Parameters
$value : string

String expression to extract characters from.

$length : int

Number of characters to return from the right.

Tags
example
use function oihana\arango\db\functions\strings\right;

$expr = right('doc.title', 10);
// Produces: 'RIGHT(doc.title, 10)'
see
https://docs.arangodb.com/stable/aql/functions/string/#right
left()

For extracting characters from the left.

subString()

For extracting characters from any position.

since
1.0.0
author

Marc Alcaraz

Return values
string

The formatted AQL expression.

rtrim()

Remove whitespace from the end of a string.

rtrim(string $value[, string|null $chars = null ]) : string

This helper wraps the ArangoDB AQL function RTRIM(value, chars) which removes whitespace characters from the end (right side) of a string. You can specify custom characters to remove instead of the default whitespace.

Example AQL usage:

RTRIM("  hello world  ")      // returns "  hello world"
RTRIM("***hello***", "*")     // returns "***hello"
RTRIM("hello  ")              // returns "hello"
RTRIM(doc.title)              // removes trailing whitespace from title
Parameters
$value : string

String expression to trim from the right.

$chars : string|null = null

Optional characters to remove (defaults to whitespace).

Tags
example
use function oihana\arango\db\functions\strings\rtrim;

$expr = rtrim('doc.title');
// Produces: 'RTRIM(doc.title)'

$expr = rtrim('doc.title', '"*"');
// Produces: 'RTRIM(doc.title, "*")'
see
https://docs.arangodb.com/stable/aql/functions/string/#rtrim
ltrim()

For trimming from the left.

trim()

For trimming from both sides.

since
1.0.0
author

Marc Alcaraz

Return values
string

The formatted AQL expression.

sha1()

Calculate the SHA1 checksum for text and return it in hexadecimal format.

sha1(string $value) : string

This helper wraps the ArangoDB AQL function SHA1(text) which calculates the SHA1 checksum for the given text and returns it as a hexadecimal string. SHA1 is a cryptographic hash function producing a 160-bit hash.

Example AQL usage:

SHA1("hello")                 // returns "aaf4c61ddcc5e8a2dabede0f3b482cd9aea9434d"
SHA1("world")                 // returns "7c211433f02071597741e6ff5a8ea34789abbf43"
SHA1(doc.content)             // returns SHA1 hash of content
Parameters
$value : string

String expression to calculate SHA1 hash for.

Tags
example
use function oihana\arango\db\functions\strings\sha1;

$expr = sha1('doc.content');
// Produces: 'SHA1(doc.content)'
see
https://docs.arangodb.com/stable/aql/functions/string/#sha1
sha256()

For SHA256 hash.

sha512()

For SHA512 hash.

md5()

For MD5 hash.

since
1.0.0
author

Marc Alcaraz

Return values
string

The formatted AQL expression.

sha256()

Calculate the SHA256 checksum for text and return it in hexadecimal format.

sha256(string $value) : string

This helper wraps the ArangoDB AQL function SHA256(text) which calculates the SHA256 checksum for the given text and returns it as a hexadecimal string. SHA256 is a cryptographic hash function producing a 256-bit hash.

Example AQL usage:

SHA256("hello")               // returns "2cf24dba4fb601a80065e1c3b8b5c9e8b8b5c9e8b8b5c9e8b8b5c9e8b8b5c9e8"
SHA256("world")               // returns "486ea46224d1bb4fb680f34f7c9ad96a8f24ec88be73ea8e5a6c65260e9cb8a7"
SHA256(doc.content)           // returns SHA256 hash of content
Parameters
$value : string

String expression to calculate SHA256 hash for.

Tags
example
use function oihana\arango\db\functions\strings\sha256;

$expr = sha256('doc.content');
// Produces: 'SHA256(doc.content)'
see
https://docs.arangodb.com/stable/aql/functions/string/#sha256
sha1()

For SHA1 hash.

sha512()

For SHA512 hash.

md5()

For MD5 hash.

since
1.0.0
author

Marc Alcaraz

Return values
string

The formatted AQL expression.

sha512()

Calculate the SHA512 checksum for text and return it in hexadecimal format.

sha512(string $value) : string

This helper wraps the ArangoDB AQL function SHA512(text) which calculates the SHA512 checksum for the given text and returns it as a hexadecimal string. SHA512 is a cryptographic hash function producing a 512-bit hash.

Example AQL usage:

SHA512("hello")               // returns a 128-character hexadecimal string
SHA512("world")               // returns a 128-character hexadecimal string
SHA512(doc.content)           // returns SHA512 hash of content
Parameters
$value : string

String expression to calculate SHA512 hash for.

Tags
example
use function oihana\arango\db\functions\strings\sha512;

$expr = sha512('doc.content');
// Produces: 'SHA512(doc.content)'
see
https://docs.arangodb.com/stable/aql/functions/string/#sha512
sha1()

For SHA1 hash.

sha256()

For SHA256 hash.

md5()

For MD5 hash.

since
1.0.0
author

Marc Alcaraz

Return values
string

The formatted AQL expression.

soundex()

Return the Soundex fingerprint of a value.

soundex(string $value) : string

This helper wraps the ArangoDB AQL function SOUNDEX(value) which returns the Soundex fingerprint of a string. Soundex is a phonetic algorithm for indexing names by sound, as pronounced in English.

Example AQL usage:

SOUNDEX("Smith")              // returns "S530"
SOUNDEX("Smyth")              // returns "S530" (same as Smith)
SOUNDEX("Johnson")            // returns "J525"
SOUNDEX(doc.name)             // returns Soundex code of name
Parameters
$value : string

String expression to calculate Soundex for.

Tags
example
use function oihana\arango\db\functions\strings\soundex;

$expr = soundex('doc.name');
// Produces: 'SOUNDEX(doc.name)'
see
https://docs.arangodb.com/stable/aql/functions/string/#soundex
https://en.wikipedia.org/wiki/Soundex
since
1.0.0
author

Marc Alcaraz

Return values
string

The formatted AQL expression.

split()

Split a string into an array using a separator.

split(string $value, string $separator[, int|null $limit = null ]) : string

This helper wraps the ArangoDB AQL function SPLIT(value, separator, limit) which splits the given string into an array of strings using the specified separator. You can optionally limit the number of splits.

Example AQL usage:

SPLIT("a,b,c", ",")           // returns ["a", "b", "c"]
SPLIT("hello world", " ")     // returns ["hello", "world"]
SPLIT("a,b,c", ",", 2)        // returns ["a", "b,c"] (limited to 2 parts)
SPLIT("hello", "")            // returns ["h", "e", "l", "l", "o"] (split by character)
Parameters
$value : string

String expression to split.

$separator : string

Separator string to split on.

$limit : int|null = null

Optional limit for number of splits.

Tags
example
use function oihana\arango\db\functions\strings\split;

$expr = split('doc.text', '","', null);
// Produces: 'SPLIT(doc.text, ",", )'
see
https://docs.arangodb.com/3.12/aql/functions/string/#split
concat()

For joining strings.

since
1.0.0
author

Marc Alcaraz

Return values
string

The formatted AQL expression.

startsWith()

Check whether a string starts with a prefix (or with one of several prefixes).

startsWith(string $value, string|array<string|int, mixed> $prefix[, int|null $minMatchCount = null ]) : string

This helper wraps the ArangoDB AQL function STARTS_WITH(text, prefix) which checks if the given string starts with the specified prefix. The comparison is case-sensitive.

Inside a SEARCH operation the ArangoSearch form STARTS_WITH(path, prefixes, minMatchCount) is also supported: pass an array of prefixes (emitted with json_encode, so plain strings are quoted) and an optional minimum number of prefixes that must match. A string prefix is kept raw, as before (callers quote it themselves).

Example AQL usage:

STARTS_WITH("hello world", "hello")       // returns true
STARTS_WITH("hello world", "world")       // returns false
STARTS_WITH("Hello world", "hello")       // returns false (case-sensitive)
STARTS_WITH(doc.text, ["lor", "ips"], 1)  // SEARCH form: at least 1 prefix matches
Parameters
$value : string

String expression to check.

$prefix : string|array<string|int, mixed>

Prefix to test for: a raw string expression (kept as-is), or an array of prefix strings (JSON-encoded).

$minMatchCount : int|null = null

Optional minimum number of prefixes that must match (ArangoSearch SEARCH form, used with an array of prefixes).

Tags
example
use function oihana\arango\db\functions\strings\startsWith;

$expr = startsWith('doc.name', '"John"');
// Produces: 'STARTS_WITH(doc.name,"John")'

$expr = startsWith('doc.text', [ 'lor' , 'ips' ] , 1 );
// Produces: 'STARTS_WITH(doc.text,["lor","ips"],1)'
see
https://docs.arangodb.com/stable/aql/functions/string/#starts_with
https://docs.arangodb.com/stable/aql/functions/arangosearch/#starts_with
contains()

For checking if string contains substring.

like()

For pattern matching.

since
1.0.0
author

Marc Alcaraz

Return values
string

The formatted AQL expression.

subString()

Return a substring of a string.

subString(string $value, int $offset[, int|null $length = null ]) : string

This helper wraps the ArangoDB AQL function SUBSTRING(value, offset, length) which extracts a substring from the given string starting at the specified offset with the optional length. Negative offsets start from the end of the string.

Example AQL usage:

SUBSTRING("hello world", 0, 5)    // returns "hello"
SUBSTRING("hello world", 6)       // returns "world"
SUBSTRING("hello world", -5)      // returns "world" (from end)
SUBSTRING("hello world", 0, 3)    // returns "hel"
Parameters
$value : string

String expression to extract substring from.

$offset : int

Starting position (0-based, negative values start from end).

$length : int|null = null

Optional length of substring (default: to end of string).

Tags
example
use function oihana\arango\db\functions\strings\subString;

$expr = subString('doc.text', 0, 10);
// Produces: 'SUBSTRING(doc.text, 0, 10)'
see
https://docs.arangodb.com/3.12/aql/functions/string/#substring
left()

For extracting from the beginning.

right()

For extracting from the end.

since
1.0.0
author

Marc Alcaraz

Return values
string

The formatted AQL expression.

toBase64()

Return the Base64 representation of a value.

toBase64(string $value) : string

This helper wraps the ArangoDB AQL function TO_BASE64(value) which converts the input value to its Base64 encoded string representation. Base64 encoding is commonly used for encoding binary data in text format.

Example AQL usage:

TO_BASE64("hello")            // returns "aGVsbG8="
TO_BASE64("world")            // returns "d29ybGQ="
TO_BASE64(doc.data)           // returns Base64 encoded data
Parameters
$value : string

String expression to encode to Base64.

Tags
example
use function oihana\arango\db\functions\strings\toBase64;

$expr = toBase64('doc.data');
// Produces: 'TO_BASE64(doc.data)'
see
https://docs.arangodb.com/3.12/aql/functions/string/#to_base64
toHex()

For hexadecimal encoding.

since
1.0.0
author

Marc Alcaraz

Return values
string

The formatted AQL expression.

toChar()

Return the character with the specified Unicode codepoint.

toChar(int $codepoint) : string

This helper wraps the ArangoDB AQL function TO_CHAR(codepoint) which returns the character corresponding to the given Unicode codepoint. This is useful for generating special characters or converting numeric codes to characters.

Example AQL usage:

TO_CHAR(65)                   // returns "A"
TO_CHAR(97)                   // returns "a"
TO_CHAR(8364)                 // returns "€" (Euro symbol)
TO_CHAR(32)                   // returns " " (space)
Parameters
$codepoint : int

Unicode codepoint to convert to character.

Tags
example
use function oihana\arango\db\functions\strings\toChar;

$expr = toChar(65);
// Produces: 'TO_CHAR(65)'
see
https://docs.arangodb.com/3.12/aql/functions/string/#to_char
since
1.0.0
author

Marc Alcaraz

Return values
string

The formatted AQL expression.

toHex()

Return the hexadecimal representation of a value.

toHex(string $value) : string

This helper wraps the ArangoDB AQL function TO_HEX(value) which converts the input value to its hexadecimal string representation. This is useful for encoding binary data or converting numbers to hex format.

Example AQL usage:

TO_HEX("hello")               // returns "68656c6c6f"
TO_HEX("world")               // returns "776f726c64"
TO_HEX(doc.data)              // returns hexadecimal representation of data
Parameters
$value : string

String expression to convert to hexadecimal.

Tags
example
use function oihana\arango\db\functions\strings\toHex;

$expr = toHex('doc.data');
// Produces: 'TO_HEX(doc.data)'
see
https://docs.arangodb.com/3.12/aql/functions/string/#to_hex
toBase64()

For Base64 encoding.

since
1.0.0
author

Marc Alcaraz

Return values
string

The formatted AQL expression.

tokens()

Split input string(s) using the specified analyzer into an array of tokens.

tokens(string $init, string $analyzer) : string

This helper wraps the ArangoDB AQL function TOKENS(input, analyzer) which splits the input text using the specified analyzer and returns an array of tokens. This is useful for text analysis and search operations.

Example AQL usage:

TOKENS("hello world", "text_en")          // returns ["hello", "world"]
TOKENS("Hello, World!", "text_en")        // returns ["hello", "world"]
TOKENS(doc.content, "text_en")            // returns tokens from content
Parameters
$init : string

Text expression to tokenize (accepts recursive arrays of strings).

$analyzer : string

Name of the analyzer to use for tokenization.

Tags
example
use function oihana\arango\db\functions\strings\tokens;

$expr = tokens('doc.content', '"text_en"');
// Produces: 'TOKENS(doc.content, "text_en")'
see
https://docs.arangodb.com/3.12/aql/functions/string/#tokens
split()

For simple string splitting.

since
1.0.0
author

Marc Alcaraz

Return values
string

The formatted AQL expression.

trim()

Removes whitespace or specific characters from the start and/or end of a string.

trim(string $value[, string|int|null $charsOrType = null ]) : string

This helper wraps the ArangoDB AQL function TRIM(value, chars) which removes whitespace characters from both ends of a string. You can specify custom characters to remove instead of the default whitespace.

  1. Whitespace mode (numeric type argument) When the second parameter is an integer, it defines which part of the string should be stripped of whitespace:
  • 0 → start and end (default)
  • 1 → start only
  • 2 → end only
TRIM("  hello  ", 0)   // "hello"
TRIM("  hello  ", 1)   // "hello  "
TRIM("  hello  ", 2)   // "  hello"
  1. Character mode (string chars argument) When the second parameter is a string, it defines a set of characters to remove from both ends of the value, instead of whitespace.
TRIM("***hello***", "*")  // "hello"
Parameters
$value : string

The string or AQL expression to trim.

$charsOrType : string|int|null = null

Optional:

  • int → whitespace mode (0, 1, 2)
  • string → characters to strip (e.g. "*")
Tags
example
use function oihana\arango\db\functions\strings\trim;

// Default (trim whitespace from both ends)
$expr = trim('doc.title');
// Produces: TRIM(doc.title)

// Trim only the start of the string
$expr = trim('doc.title', 1);
// Produces: TRIM(doc.title, 1)

// Trim custom characters
$expr = trim('doc.title', '"*"');
// Produces: TRIM(doc.title, "*")
see
https://docs.arangodb.com/stable/aql/functions/string/#trim
ltrim()

For trimming from the left only.

rtrim()

For trimming from the right only.

since
1.0.0
author

Marc Alcaraz

Return values
string

The AQL expression representing the TRIM() call.

upper()

Convert lowercase letters to uppercase.

upper(string $value) : string

This helper wraps the ArangoDB AQL function UPPER(value) which converts all lowercase letters in a string to their uppercase counterparts while leaving all other characters unchanged.

Example AQL usage:

UPPER("hello world")           // returns "HELLO WORLD"
UPPER("123 abc")               // returns "123 ABC"
UPPER(doc.title)               // converts title to uppercase
Parameters
$value : string

String expression to convert to uppercase.

Tags
example
use function oihana\arango\db\functions\strings\upper;

$expr = upper('doc.title');
// Produces: 'UPPER(doc.title)'
see
https://docs.arangodb.com/stable/aql/functions/string/#upper
lower()

For converting to lowercase.

since
1.0.0
author

Marc Alcaraz

Return values
string

The formatted AQL expression.

uuid()

Return a universally unique identifier (UUID).

uuid() : string

This helper wraps the ArangoDB AQL function UUID() which generates and returns a universally unique identifier. UUIDs are useful for generating unique identifiers that are globally unique across different systems and time periods.

Example AQL usage:

UUID()                        // returns something like "550e8400-e29b-41d4-a716-446655440000"
UUID()                        // returns a different UUID each time
Tags
example
use function oihana\arango\db\functions\strings\uuid;

$expr = uuid();
// Produces: 'UUID()'
see
https://docs.arangodb.com/3.12/aql/functions/string/#uuid
randomToken()

For generating random tokens.

since
1.0.0
author

Marc Alcaraz

Return values
string

The formatted AQL expression.

On this page

Search results