Strings


Literal strings or characters used as arguments to these functions must be surrounded by single quotes, '...'. For example: isalpha('r2d2'). These functions do not modify their arguments; they return values based on those arguments.

Name -- Syntax / Description
asciichar
asciichar( number )
Returns the character corresponding to ascii character code in number. (number must be less than 255).
asciivalue
asciivalue( character )
Returns the ASCII numeric value for character (character must be a single character).
decodeattribute
decodeattribute( attribute )
Returns a copy of string (which is usually a URL) converted from URL-encoded format to ordinary text. This function is the opposite of encodeattribute.
decodeentities
decodeentities( string )
Returns a copy of string in which all HTML entities have been converted to their plain text equivalents (for example, & is converted to &). This function is the opposite of encodeentities.
encodeattribute
encodeattribute( attribute )
Returns a copy of string (which is usually a URI or part of an URI ) in URI-encoded format. Special characters such as space, tilde (~), and the plus sign are converted to hexadecimal %nn format. This function is the opposite of decodeattribute.
A URI encoded string
encodeentities
encodeentities( string )
Returns a copy of string in which all characters have been converted to their HTML entity equivalents, where applicable (for example, & is converted to "&"). This function is the opposite of decodeentities.
encodejavascriptstring
encodejavascriptstring( string )
Encodes "string" in a format suitable for use inside a JavaScript quoted string declaration, honoring the current character set.
Returns the encoded string.
  • string = the string that will be encoded.
gettoken
gettoken( delimited_string, characters, position_num )
Returns the nth number token (i.e. substring) of a delimited_string using characters as token separators. A null string is returned if there is no nth token. Common delimiter characters are comma, tab, linefeeds, pipe but are not limited to these.
Returns the position_num token (i.e. substring) of a delimited_string delimited by characters.
  • delimited_string = A string delimited by a character or characters
  • characters = the delimiter character or characters
  • position_num = the position of the substring you want to return
glosub
glosub( target_string, search, replace )
Global substitution returns a copy of string in which all instances of string search have been replaced by string replace. (Note: to represent a backslash () in replace, use '\\').
Returns string where all instances of search have been replaced.
  • target_string = the target string
  • search = the sub-string that will be search ed for
  • replace = the replacement string
glosub_array
glosub_array( string, search_array, replace_array )
Works like glosub(), but search_array and replace_array are iterated through, each value in search_array found in the string is replaced by the corresponding value in replace_array
Return Value: string is returned with all found values replaced.
  • string = the target
  • search_array = an array of strings that will be searched for
  • replace_array = an array of the replacement strings
indexof
indexof( search_string, target_string var, start_number )
Returns the position of the first occurrence of search_string within the target_string beginning at the start_number position. The search is CASE SENSITIVE sensitive. If not found, the functions return 0. The offset parameter and returned string offset are 1-based. For speed, target_string is passed by reference .
Returns the 1 based offset_number of search_string within the target_string. The search is case sensitive.
  • search_string = the string that will be searched for
  • target_string = the string that will be searched
  • start_number = the 1 based starting offset withing the target_string where the search will begin
indexofi
indexofi( search_string, target_string var, start_number )
Returns the position of the first occurrence of search_string within the target_string beginning at the start_number position. The search is CASE IN-SENSITIVE. If not found, the functions return 0. The offset parameter and returned string offset are 1-based. For speed, target_string is passed by reference
Returns the 1 based offset_number of search_string within the target_string. The search is case in-sensitive.
  • search_string = the string that will be searched for
  • target_string = the string that will be searched
  • start_number = the 1 based starting offset withing the target_string where the search will begin
indexofl
indexofl( needle, haystack var, offset )
Search from the end of the haystack for needle, starting at the offset position.
Return value: Index of found value, or 0 if not found.
  • needle var = Value to search for.
  • haystack var = Text to search.
  • offset = integer offset to start at.
indexofli
indexofli( needle, haystack var, offset )
Search without regard to case from the end of the haystack for needle, starting at the offset position.
Return value: Index of found value, or 0 if not found.
  • needle var = Value to search for.
  • haystack var = Text to search.
  • offset = integer offset to start at.
isalnum
isalnum( string )
Test if all characters are either alphabetic or digits
Returns 1 if true, 0 if false
  • string = the characters tested
isalpha
isalpha( string )
Test if all characters are alphabetic.
Returns 1 if true, 0 if false
  • string = the characters tested
isascii
isascii( string )
Test if all characters are ASCII characters (those with decimal value between 0 and 127).
Returns 1 if true, 0 if false
  • string = the characters tested
iscntrl
iscntrl( string )
Test if all characters are control characters (those with decimal value between 0 and 31, or 127).
Returns 1 if true, 0 if false
  • string = the characters tested
isdigit
isdigit( string )
Test if all characters are digits in the range 0-9.
Returns 1 if true, 0 if false
  • string = the characters tested
isgraph
isgraph( string )
Test if all characters are graphic (see isprint) characters (those with decimal value between 33 and 127).
Returns 1 if true, 0 if false
  • string = the characters tested
islower
islower( string )
Test if all characters are lowercase letters,
Returns 1 if true, 0 if false
  • string = the characters tested
isprint
isprint( string )
Test if all characters are printable (same as graphic characters, with the addition of the space character).
Returns 1 if true, 0 if false
  • string = the characters tested
ispunct
ispunct( string )
Test if all characters are whitespace (space, tab, vertical tab, newline, form feed) characters.
Returns 1 if true, 0 if false
  • string = the characters tested
isspace
isspace( string )
Test if all characters are whitespace (space, tab, vertical tab, newline, form feed) characters.
Returns 1 if true, 0 if false
  • string = the characters tested
isupper
isupper( string )
Test if all characters are uppercase letters.
Returns 1 if true, 0 if false
  • string = the characters tested
isxdigit
isxdigit( string )
Test if all characters are hexadecimal digits (a-f, A-F, 0-9).
Returns 1 if true, 0 if false
  • string = the characters tested
keyword_extract
keyword_extract( string, keywords var )
Given a string, will extract keywords from it. Skipping SGML tags and stemming words (e.g., "running" becomes "run", but "bring" is not changed), the unique list of keywords are placed in the keywords as an array. Also, some common english words (the articles, "for" "are", etc.) are removed. Note that there are some words may stem unexpectedly (e.g., "has" transforms to "ha").
Populates the keywords array and returns number of elements.
keyword_extract_merge
keyword_extract_merge( string, weight )
Extracts keywords as described in keyword_extract, but inserts them into a persistent array initialized by keyword_extract_merge_init. The weight value passed in is associated with the results from the current string being analyzed. Return null.
Returns null.
keyword_extract_merge_init
keyword_extract_merge_init()
Initializes persistent storage for a multiple calls to keyword_merge_extract. Note that this persistent storage is usable for multiple calls within a running Miva Script program, and is deleted by the VM at the end of program execution.
Returns null.
keyword_extract_merge_results
keyword_extract_merge_results( keywords var )
Returns results from one or more keyword_extract_merge calls, storing them as an aggregate in "keywords".
Returns null.
keyword_in
keyword_in( keywords_array var, search_string )
Performs a keyword_extract() on the string parameter, and determines if the value in the keywords parameter is contained in the keyword list, and returns a boolean 1 or 0 to signify that the keyword is or is not in the string. If the keywords parameter is an array of strings, checks each value in the array, and returns an array of booleans specifying whether the array element is or is not in the string.
If keywords is an array, returns an array of booleans specifying if a given keyword element is in the keyword list. -- If keywords is a string, returns a boolean specifying if the given keyword is in the keyword list.
len
len( string )
Returns the number of characters in string.
The length of string.
  • string = a literal string value embedded in single quotes or an expression that evaluates as a string.
len_var
len_var( string var )
Returns the number of characters in string. This function is identical to len() but its parameter is passed by reference, improving performance when dealing with large strings.
the length of the string
  • string = a literal string value embedded in single quotes or an expression that evaluates as a string.
ltrim
ltrim( string )
Returns a copy of string with all space characters removed from the left end.
miva_cdata_encode
miva_cdata_encode( text )
Create one or more CDATA tags with the provided text, splitting any data with "]]>" into two CDATA tags with "]]" at the end of one CDATA tag, and ">" as the first value of the next CDATA tag.
Return value: Text quoted within one or more CDATA tags.
  • text = String to encode
miva_csv_encode
miva_csv_encode( text, delimiter )
miva_hex_decode
miva_hex_decode( data )
Convert "data" to hexadecimal notation.
returns the resulting decoded data
  • data = the hex data to decode.
miva_hex_encode
miva_hex_encode( data )
Convert "data" to hexadecimal notation.
returns the resulting encoded data.
  • data = the value to encode.
miva_json_decode
miva_json_decode( data, output var )
Decodes a block of JSON data in "data", returning the parsed aggregate value in "output".
Returns 1 on success, 0 on error.
  • data = The block of JSON encoded data that will be decoded output var = The function assigns the parsed aggregate to "output" as a structured array.
miva_json_decode_last_error
miva_json_decode_last_error()
Returns a text description of the most recent parsing error encountered by miva_json_decode()
Returns a text description of the most recent parsing error.
miva_splitstring
miva_splitstring( string, sep, output var, flags )
Splits a string into chunks in an array, using the separator parameter as the point to split the string. Returns the number of elements in the output array.
Returns: The number of elements in the output array.
  • string = The input string
  • sep = A single character that will be used to split the string into multiple elements (for example a comma or space)
  • output var - The array of elements returned
  • flags - A comma separated list of any of the following keywords
    trim : removes extra space around the left and right sides of all elements
    ltrim : removes extra space around the left side of all elements
    rtrim : removes extra space around the right side of all elements
    lower : converts all elements to lowercase
    upper : converts all elements to uppercase
    insensitive : searches for the sep input parameter using a case-insensitive search
padl
padl( string, length, character )
Returns a string length characters long, consisting of string padded on the left with as many instances of padcharacter as are needed to make up the full length.
padr
padr( string, length, character )
Returns a string length characters long, consisting of string padded on the right with as many instances of padcharacter as are needed to make up the full length.
rtrim
rtrim( string )
Returns a copy of string with all space characters removed from the right end.
slugify
slugify( data )
Use this function to create friendly (human-readable) URLs. It takes characters that are forbidden in URIs and either converts them to a valid ASCII character or remove them completely. It adds a hyphen (-) in place of all space characters. For example, the product "Dodger Blue Baseball Hat!" becomes "Dodger-Blue-Baseball-Hat" which is now URI friendly.
A URL friendly string.
substring
substring( string, position, length )
Returns the substring of string, beginning at position start, length characters long.
substring_var
substring_var( string var, position, length )
Returns the substring of string, beginning at position start, length characters long. This function is identical to substring() but its first parameter is passed by reference, improving performance when dealing with large strings.
tokenize
tokenize( string, variables )
Returns the string, concatenated with the value of each token contained in replacements. Replacements is an array of structures, each with a token and a value.
tolower
tolower( string )
Returns a copy of string in lower case.
toupper
toupper( string )
Returns a copy of string in upper case.
trim
trim( string )
Returns the value of string with leading and trailing spaces removed
crypto_base64_decode
crypto_base64_decode( data )
Decodes and returns Base-64 decodes data.
Returns the decrypted data
  • data = the information to decode
crypto_base64_encode
crypto_base64_encode( data )
Encodes and returns Base-64 encoded data.
Returns the encrypted data
  • data = the information to encode
miva_html_strip
miva_html_strip( text, allowed_tags )
Removes HTML tags from a given string.
Return value: Text string with all HTML tags except those listed in allowed_tags removed.
  • text = String to remove HTML tags from.
  • allowed_tags = A comma-separated list of tags that will not be stripped from the string.
miva_variable_value
miva_variable_value( string )
Returns the value of a variable where expression is the literal name of the variable.
User Annotations: strings