Skip to main content

PHP Functions Available for Kuroco's Smarty

You can use Smarty plugins for custom functions or batch processes in Kuroco.
This document provides the list of the PHP functions that can be used as modifiers for variables.

Available PHP Functions

if Statement

The following PHP functions can be used with the {if} statement in Kuroco's Smarty.

PHP FunctionDescription
is_nullChecks if a variable is null
countCounts all elements in an array or Countable object
is_arrayChecks if a variable is an array
in_arrayChecks if a value exists in an array
issetChecks if a variable is declared and is not null
is_objectChecks if a variable is an object

Example

{if is_null($hoge)}
$hoge is null.
{/if}

Modifiers

The following PHP functions can be used as modifiers for variables in Kuroco's Smarty.

PHP Function NameDescription
array_columnReturns the values from a single column of an input array
array_key_existsChecks if a specified key or index exists in an array
array_keysReturns all the keys of an array, or a subset of the keys
array_mergeMerges one or more arrays
array_popRemoves an element from the end of an array
array_pushPushes one or more elements onto the end of an array
array_reverseReturns an array with elements in reverse order
array_shiftRemoves the first element from an array and returns it
array_sliceExtracts a slice of an array
array_uniqueRemoves duplicate values from an array
array_valuesReturns all the values of an array
arsortSorts an array in reverse order, maintaining the key to element relationship
asortSorts an array in ascending order, maintaining the key to element relationship
base64_decodeDecodes data encoded with MIME base64
base64_encodeEncodes data with MIME base64
explodeSplits a string by a string
filter_varFilters a variable with a specified filter
floorRounds a number down to the nearest integer
html_entity_decodeConverts HTML entities to their corresponding characters
htmlspecialchars_decodeConverts special HTML entities back to characters
http_build_queryGenerates a URL-encoded query string
implodeJoins array elements with a string
intvalReturns the integer value of a variable
is_arrayChecks if a variable is an array
is_numericChecks if a variable is a number or a numeric string
json_decodeDecodes a JSON string
json_encodeReturns a JSON encoded string
keyFetches a key from an array
krsortSorts an array by key in reverse order
ksortSorts an array by key in ascending order
maxReturns the highest value in an array
mb_convert_encodingConverts a string from one character encoding to another
mb_convert_kanaConverts Kana characters to a specific Kana type
mb_strimwidthTruncates a string to a specified width
mb_striposFinds the position of the first occurrence of a case-insensitive string within another string
mb_strlenReturns the length of a string
mb_strposFinds the position of the first occurrence of a string inside another string
mb_strwidthReturns the width of a string
mb_substrReturns part of a string
md5Calculates the MD5 hash of a string
minReturns the lowest value in an array
mt_randGenerates a random number using the Mersenne Twister random number generator
nl2brInserts HTML line breaks before all newlines in a string
number_formatFormats a number with grouped thousands
parse_urlParses a URL and returns its components
pathinfoReturns information about a file path
property_existsChecks if an object or class has a property
rangeCreates an array containing a range of elements
rawurldecodeDecodes a URL-encoded string
roundRounds a float to the nearest integer
rsortSorts an array in reverse order
shuffleShuffles an array
sortSorts an array in ascending order
str_padPads a string to a certain length with another string
strip_tagsStrips HTML and PHP tags from a string
striposFinds the position of the first occurrence of a string inside another string, case-insensitive
strlenReturns the length of a string
strposFinds the position of the first occurrence of a string inside another string
strstrFinds the position of the first occurrence of a string inside another string
strtolowerConverts a string to lowercase
strtotimeConverts an English textual datetime description to a Unix timestamp
strtoupperConverts a string to uppercase
strvalReturns the string value of a variable
substrReturns a part of a string
trimRemoves whitespace from the beginning and end of a string
unsetUnsets a specified variable
urlencodeURL-encodes a string
  • Specify the variable as the first argument of the function and the function name as the modifier. For the second and subsequent arguments, write them after the modifier separated by a colon (:).
  • If the variable is an array, prefix the function name with an @ sign.
  • Please refer to the List of Constants Available in Kuroco for the PHP predefined constants used in functions.

Example (for array_column)

{* Example of a record set returned from a database *}
{assign_array var="records" values=""}

{assign_array var="record" values=""}
{append var="record" index="id" value=2135}
{append var="record" index="first_name" value="John"}
{append var="record" index="last_name" value="Doe"}
{append var="records" value=$record}

{assign_array var="record" values=""}
{append var="record" index="id" value=3245}
{append var="record" index="first_name" value="Sally"}
{append var="record" index="last_name" value="Smith"}
{append var="records" value=$record}

{assign_array var="record" values=""}
{append var="record" index="id" value=5342}
{append var="record" index="first_name" value="Jane"}
{append var="record" index="last_name" value="Jones"}
{append var="records" value=$record}

{assign_array var="record" values=""}
{append var="record" index="id" value=5623}
{append var="record" index="first_name" value="Peter"}
{append var="record" index="last_name" value="Doe"}
{append var="records" value=$record}

{* Specify the variable as the first argument of the function and the function name as the modifier. For the second and subsequent arguments, write them after the modifier separated by a colon (`:`) *}
{* If the variable is an array, prefix the function name with an at sign (`@`) *}
{assign var="first_names" value=$records|@array_column:'first_name'}

{$first_names|@debug_print_var}

Output

Array (4)
0 => "John"
1 => "Sally"
2 => "Jane"
3 => "Peter"

Example (for str_pad)

{assign var=input value="Alien"}
{assign var=output value=$input|str_pad:10:"_":$smarty.const.STR_PAD_BOTH}

{$input|debug_print_var}
{$output|debug_print_var}

Output

"Alien"
"__Alien___"

Support

If you have any other questions, please contact us or check out Our Slack Community.