Zeta Components - high quality PHP components

Template Functions

Table of Contents

Array functions

Date functions

Debugging functions

Math functions

Regular expression functions

String functions

Type functions

Web functions

Array

int array_count ( array $a )

Returns the count of elements contained in an array:

{array_count( array( 1, 2, 3, 4 ) )}

returns the value 4.

bool array_is_empty ( array $a )

Returns true if an array contains an element:

{array_is_empty( array( 1, 2, 3 ) )}

will evaluate to false, while:

{array_is_empty( array() )}

gives true.

bool array_contains ( array $a, mixed $v )

Returns true if the value $v exists in the array $a:

{array_contains( array( 1, 2, 3 ), 2 )}

will evaluate to true, while:

{array_contains( array( 1, 2, 3 ), 4 )}

gives false.

See also array_index_of (), array_find (), array_index_exists ().

bool array_index_exists ( array $a, mixed $index )

Returns whether an $index exists in an array:

{array_index_exists( array( 1, 2, 3 ), 1 )}

will return true, while:

{array_index_exists( array( 1, 2, 3 ), 10 )}

returns false.

See also array_index_of (), array_contains (), array_find ().

mixed array_index_of ( array $a, mixed $v )

Returns the index of a specific element value ($v) in the array or boolean false, when the element is not contained in the array:

{array_index_of( array( "a" => "b", "c" => "d" ), "b" )}

will return "a", while:

{array_index_of( array( "a" => "b", "c" => "d" ), "c" )}

will return false, since "c" is not an element contained in the array.

See also array_find (), array_contains (), array_index_exists ().

array array_left ( array $a, int $len )

Returns the left part of an array with the specified length ($len):

{array_left( array( 1, 2, 3, 4 ), 2 )}

returns the following array:

array( 1, 2 )

See also array_right (), array_mid ().

array array_right ( array $a, int $len )

Returns the right part of an array with the specified length ($len):

{array_right( array( 1, 2, 3, 4 ), 2 )}

returns the following array:

array( 3, 4 )

See also array_left (), array_mid ().

array array_mid ( array $a, int $index, int $len )

Returns a part from the middle of an array, that starts at a specific $index with the specified length ($len):

{array_mid( array( 1, 2, 3, 4 ), 1, 2 )}

returns the following array:

array( 2, 3 )

See also array_left (), array_right ().

array array_insert ( array $a, int $index, mixed $v1 [, mixed $v2 ...] )

Returns an array, where the additional elements $v1, $v2, ... have been inserted into the source array ($a) starting from $index:

{array_insert( array( 1, 2, 3 ), 1, "a", "b" )}

returns the following array:

array( 1, "a", "b", 2, 3 )

See also array_prepend (), array_append (), array_pad ().

array array_append ( array $a, mixed $v1 [, mixed $v2 ...] )

Returns an array with the additional values $v1, $v2, ... appended to the original array ($a):

{array_append( array( 1, 2, 3 ), 4, 5 )}

returns the following array:

array( 1, 2, 3, 4, 5 )

See also array_prepend (), array_insert (), array_pad ().

array array_prepend ( array $a, mixed $v1 [, mixed $v2 ...] )

Returns an array with the additional values $v1, $v2, ... prepended to the original array ($a):

{array_prepend( array( 1, 2, 3 ), 4, 5 )}

returns the following array:

array( 4, 5, 1, 2, 3 )

See also array_append (), array_insert (), array_pad ().

array array_pad ( [array $a = array(),] int $len, mixed $fill )

Fills an array $a with the given fill value $fill up to the length len. If the submitted array already contains values, those will not be overwritten:

{array_pad( array( 1, 2, 3 ), 5, "a" )}

returns the following array:

array( 1, 2, 3, "a", "a" )

See also array_append (), array_insert (), array_prepend (), array_fill_range ().

array array_fill_range ( int $low, int $high [, int $step] )

Returns an array of elements $from low to $high, inclusive. If $low > $high, the sequence will be from $high to $low. If a $step value is given, it will be used as the increment between elements in the sequence. $step should be given as a positive number. If not specified, step will default to 1:

{array_fill_range( 0, 10, 2 )}

returns the following array:

array( 0, 2, 4, 6, 8, 10 )

See also array_pad ().

array array_repeat ( array $a, int $len )

Returns a multidimensional array, which has $len elements, which all contain the array $a:

{array_repeat( array( 1, 2 ), 2 )}

returns an array:

array( array( 1, 2 ), array( 1, 2 ) )

array array_remove ( array $a, mixed $index [, int $len] )

Returns an array which results from the given array, where the portion starting at $index and with the length $len has been removed:

{array_remove( array( 1, 2, 3, 4, 5 ), 1, 2 )}

returns the following array:

array( 1, 4, 5 )

See also array_remove_first (), array_remove_last ().

array array_remove_first ( array $a [, int $len] )

Returns an array with the first part with the specified length $len of the original array ($a) removed. If $len is omitted, 1 is assumed and the first element is removed:

{array_remove_first( array( 1, 2, 3, 4 ), 2 )}

returns the following array:

array( 3, 4 )

See also array_remove_last (), array_remove ().

array array_remove_last ( array $a [, int $len] )

Returns an array with the last part with the specified length $len of the original array ($a) removed. If $len is omitted, 1 is assumed and the last element is removed:

{array_remove_last( array( 1, 2, 3, 4 ), 2 )}

returns the following array:

array( 1, 2 )

See also array_remove_first (), array_remove ().

mixed array_find ( array $a, mixed $v )

Returns the key of the submitted value $v in the submitted array $a. If the value is not found, this function returns boolean false:

{array_find( array( 1, 2, 3, 4 ), 3 )}

returns the key 2.

See also array_index_of (), array_contains (), array_index_exists (), array_find_replace ().

array array_find_replace ( array $a, mixed $v, mixed $vNew )

Returns an array where a specific value $v1 from the original array $a has been replaced with the new value $vNew:

{array_find_replace( array( 1, 2, 3 ), 2, "a" )}

returns the following array:

array( 1, "a", 3 )

See also array_replace (), array_find ().

array array_replace ( array $a, mixed index, int $len = 1, mixed $v1 [, mixed*$v2* ...] )

Returns an array, where a given part in the original array has been replaced. The part to replace starts with $index and is $len elements long. The defined portion is replaced with the given values $v1, $v2,...

{array_replace( array( 1, 2, 3, 4 ), 1, 2, "a", "b", "c" )}

returns the following array:

array( 1, "a", "b", "c", 4 )

See also array_find_replace ().

array array_swap ( array $a, mixed $index1, mixed $index2 )

Returns an array where the 2 indices $index1 and $index2 are swapped:

{array_swap( array( 1, 2, 3, 4 ), 1, 3 )}

returns the following array:

array( 1, 4, 3, 2 )

array array_reverse ( array $a )

Returns an array where the elements are in reverse order as for the original array:

{array_reverse( array( 1, 2, 3 ) )}

returns the following array:

array( 3, 2, 1 )

array array_merge ( array $a1, array $a2 [, array $a3 ..] )

Returns 2 or more arrays merged into 1 single array:

{array_merge( array( "a" => "a", "b" => "b", "c" => "c" ), array( "a" => 1, "c" => 2 ) )}

returns the following array:

array( "a" => 1, "b" => "b", "c" => 2 )

See also array_intersect (), array_diff ().

array array_diff ( array $a1, array $a2 [, array $a3 ...] )

Returns an array containing all the values of $a1 that are not present in any of the other arguments ($a2, $a3,...):

{array_diff( array( 1, 2, 3, 4 ), array( 2, 4 ), array( 5 ) )}

returns the following array:

array( 1, 3 )

See also array_intersect (), array_merge ().

array array_intersect ( array $a1, array $a2 [, array $a3 ...] )

Returns an array containing all the values of $a1 that are present in all the other arguments ($a2, $a3,...):

{array_intersect( array( 1, 2, 3, 4 ), array( 2 ), array( 4 ) )}

returns the following array:

array( 2, 4 )

See also array_merge (), array_diff ().

array array_unique ( array $a )

Returns the submitted array without any duplicate values:

{array_unique( array( 1, 2, 2, 3, 2, 4, 2, 2 ) )}

returns the following array:

array( 1, 2, 3, 4 )

array array_sum ( array $a )

Returns the sum of the elements in the given array:

{array_sum( array( 5, 5, 10, 20 ) )}

returns 40.

array array_extract_by_properties ( array $a, array $pList )

Returns an array of extracted properties from an array of objects. The properties named in the $pList array. Each property becomes a new value in the resulting array:

{use $productsArray} {var $priceArray = array_extract_by_properties( $productsArray, array( "price" ) )} {debug_dump( $priceArray )}

The first line of the code above imports an array with product objects. A product object has at least one property price. Meaning that:

{$productArray[0]->price}

returns the price of the first product in the array. The function array_extract_by_properties goes through the whole array of products and stores the price in the array. The output can be something like:

array ( [0] => 200 [1] => 199.24 [2] => 50.20 )

array hash_diff ( array $a1, array $a2 [, array $a3 ...] )

Returns an array containing all the values of $a1 that are not present in any of the other arguments ($a2, $a3,...). With this function (in contrast to array_diff) the keys are considered, too:

{hash_diff( array( "a" => "a", "b" => "b" ), array( "a" => "a", "c" => "b" ) )}

returns the following array:

array( "b" => "b" )

See also hash_diff_key (), hash_intersect (), hash_intersect_key ().

array hash_diff_key ( array $a1, array $a2 [, array $a3 ...] )

Returns an array containing all the values of $a1 that are not present in any of the other arguments ($a2, $a3,...). With this function (in contrast to array_diff) the keys are used for comparison:

{hash_diff_key( array( "a" => "a", "b" => "b" ), array( "a" => "a", "c" => "b" ) )}

returns the following array:

array( "b" => "b" )

See also hash_diff (), hash_intersect (), hash_intersect_key ().

array hash_intersect ( array $a1, array $a2 [, array $a3 ...] )

Returns an array containing all the values of $a1 that are present in all the other arguments ($a2, $a3,...). In contrast to array_intersect this function performs additional key checks:

{hash_intersect( array( "a" => "a", "b" => "b" ), array( "a" => "a", "b" => "c" ) )}

returns the following array:

array( "a" => "a" )

See also hash_intersect_key (), hash_diff_key (), hash_diff ().

array hash_intersect_key ( array $a1, array $a2 [, array $a3 ...] )

Returns an array containing all the values of $a1 that are present in all the other arguments ($a2, $a3,...). In contrast to array_intersect this function checks the keys instead of the values:

{hash_intersect_key( array( "a" => "a", "b" => "b" ), array( "a" => "a", "b" => "c" ) )}

returns the following array:

array( "a" => "a", "b" => "c" )

See also hash_intersect (), hash_diff (), hash_diff_key ().

array hash_keys ( array $a )

Returns the keys of the provided array as an array:

{hash_keys( array( "a" => 1, "b" => 2 ) )}

returns the following array:

array( "a", "b" )

See also hash_values ().

array hash_values ( array $a )

Returns the values of the provided array as an array:

{hash_values( array( "a" => 1, "b" => 2 ) )}

returns the following array:

array( 1, 2 )

See also hash_keys ().

array hash_flip ( array $a )

Returns an array, which has the values of the original array $a as the keys, which are assigned to the keys of the original array:

{hash_flip( array( "a" => "apple", "b" => "banana", "c" => "banana" ) )}

returns the following array:

array( "apple" => "a", "banana" => "c" )

array array_sort ( array $a )

Returns a sorted version of the array:

{array_sort( array( 1, 3, 2, 5, 4 ) )}

returns the following array:

array( 1, 2, 3, 4, 5 )

See also hash_sort (), hash_sort_keys (), array_sort_reverse ().

array array_sort_reverse ( array $a )

Returns a sorted version of the array, but in reverse order:

{array_sort_reverse( array( 1, 3, 2, 5, 4 ) )}

returns the following array:

array( 5, 4, 3, 2, 1 )

See also hash_sort (), hash_sort_keys (), array_sort ().

array hash_sort ( array $a )

Returns a sorted version of the array, maintaining the key => value association:

{hash_sort( array( "a" => "banana", "b" => "apple" ) )}

returns the following array:

array( "b" => "apple", "a" => "banana" )

See also array_sort (), hash_sort_keys (), hash_sort_reverse ().

array hash_sort_reverse ( array $a )

Returns a reverse sorted version of the array, maintaining the key => value association:

{hash_sort_reverse( array( "a" => "banana", "b" => "apple" ) )}

returns the following array:

array( "a" => "banana", "b" => "apple" )

See also hash_sort (), hash_sort_keys (), array_sort ().

array hash_sort_keys ( array $a )

Returns a sorted version of the array, sorted by the keys of the array, maintaining the key => value association:

{hash_sort_keys( array( "a" => "banana", "b" => "apple" ) )}

returns the following array:

array( "a" => "banana", "b" => "apple" )

See also hash_sort (), array_sort (), hash_sort_keys_reverse ().

array hash_sort_keys_reverse ( array $a )

Returns a sorted version of the array, sorted by the keys of the array in reverse order, maintaining the key => value association:

{hash_sort_keys_reverse( array( "a" => "banana", "b" => "apple" ) )}

returns the following array:

array( "b" => "apple", "a" => "banana" )

See also hash_sort_keys (), hash_sort (), array_sort ().

Date

string date_format ( string $format, DateTime $time )

Returns a formatted string that represents the time belonging to the DateTime object $time.

The format is the same as the format from the PHP date function:

The next example:

{date_format( "H:i:s", $time )}

Shows something like:

08:09:53

Be aware that you have to send $time as a DateTime object, and not as an integer timestamp.

string date_format_timestamp ( string $format [, int $timestamp] )

Returns a formatted string that represents the time. If no $timestamp is given then the current time will be returned, otherwise the time of the $timestamp will be returned.

The format is the same as the format from the PHP date function:

The next example:

{date_format_timestamp( "H:i:s" )}

Shows something like:

22:10:45

int date_current_timestamp ()

Returns the current timestamp. The timestamp is measured in the number of seconds since the Unix Epoch (January 1 1970 00:00:00 GMT):

{date_current_timestamp()}

Outputs something like the next line, but the number is probably higher:

1147362767

Debugging

string debug_dump ( mixed $val )

Returns a string that shows human readable debug information about the given value $val. This function should only be used for debugging purposes during development of your templates. The next example shows the contents of a variable:

{var $a = array( "Bernard" => "Black", "Manny", 42 )} {debug_dump( $a )}

Outputs:

array ( 'Bernard' => 'Black', 0 => 'Manny', 1 => 42, )

Math

int math_max ( float $val1 , float $val2 [, ...] )

Returns the maximum number of the given values:

{math_max( 5, 3.14, 22.1 )}

Outputs:

22.1

int math_min ( float $val1 , float $val2 [, ...] )

Returns the minimum number of the given values:

{math_min( 5, 3.14, 22.1 )}

Outputs:

3.14

float math_abs ( float $val )

Returns the absolute number the given value $val:

{math_abs( -5.2 )} {math_abs( 3.14 )}

Outputs:

5.2 3.14

int math_ceil ( float $val )

Returns an upwards rounded number of the value $val.:

{math_ceil( 3.14 )} {math_ceil( -5.2 )}

Outputs:

4 -5

int math_floor ( float $val )

Returns a downwards rounded number of the value $val.:

{math_floor( 3.14 )} {math_floor( -5.2 )}

Outputs:

3 -6

int math_round ( float $val )

Returns a rounded number of the value $val. The fractions from 0 until 4 are rounded downwards, fractions from 5 until 9 are rounded upwards:

{math_round( 3.5 )} {math_round( 4.5 )} {math_round( 5.49999 )}

Outputs:

4 5 5

float math_sqrt ( float $val )

Calculates and returns the square root of $val:

{math_sqrt( 9 )} {math_sqrt( 10 )}

Outputs:

3 3.16227766

float math_exp ( float $val )

Calculates and returns the exponent (e) raised to the power of $val:

{math_exp( 12 )} {math_exp( 5.7 )}

Outputs:

162754.791419 298.86740096706

int math_pow ( int $base, int $exp )

Returns the $base raised to the power of the $exp:

{math_pow( 2, 4 )}

Outputs:

16

float math_log ( int $arg, int $base )

Returns the logarith of Log $base $arg:

{math_log( 16, 2 )}

Outputs:

4

float math_log10 ( int $arg )

Returns the 10-base logarithm of the argument:

{math_log10( 10000 )}

Outputs:

4

float math_float_mod ( float $x, float $y )

Returns the floating point remainder of a devision of the arguments. It checks how many times the value $y 'fits in' the value $x. A The remainder is returned:

{math_float_mod( 3.7, 1.1 )}

Outputs:

0.4

Because the 1.1 fits 3 times in 3.7, and therefore:

3 * 1.1 = 3.3 3.7 - 3.3 = 0.4

int math_rand ( int $min, int $max )

Returns a random integer value between $min and $max:

{math_rand( 2, 7 )}

float math_pi ()

Returns the number Pi:

{math_pi()}

Outputs:

3.1415926535898

bool math_is_finite ( $val )

Returns true if $val is finite, otherwise false:

{math_is_finite( 7 )}

This example would return true.

bool math_is_infinite ( $val )

Returns true if $val is infinite, otherwise false:

{math_is_infinite( math_log(0, 2.7 ) )}

This example would return true.

int math_bin_to_dec ( string $str )

Returns the decimal integer value of the binary string $str:

{math_bin_to_dec( "01011" )}

Outputs:

11

string math_dec_to_bin ( int $val )

Returns the binary string of the value $val:

{math_dec_to_bin( 11 )}

Outputs:

1011

int math_hex_to_dec ( string $str )

Returns the decimal integer value of the hexadecimal string $str:

{math_hex_to_dec( "10" )} {math_hex_to_dec( "a" )}

Outputs:

16 10

string math_dec_to_hex ( int $val )

Returns the hexidecimal string of the value $val:

{math_dec_to_hex( 16 )} {math_dec_to_hex( 10 )}

Outputs:

10 a

int math_oct_to_dec ( string $str )

Returns the decimal integer value of the octal string $str:

{math_oct_to_dec( "12" )}

Outputs:

10

string math_dec_to_oct ( int $val )

Returns the octal string of the value $val:

{math_dec_to_oct( 10 )}

Outputs:

12

Regular expressions

bool preg_has_match ( string $subject, string $pattern )

Returns true if the given regular expression $pattern* matches with the $subject, otherwise false. The syntax of the pattern is described here.

The next example returns true because the pattern matches the subject:

{preg_has_match( "Bernard Black", "/^B.*/" )}

array preg_match ( string $subject, string $pattern )

Returns an array with the matching values of the performed match between the regular expression $pattern and the $subject. The syntax of the pattern is described here.

The next example returns true because the pattern matches the subject:

{var $matches = preg_match( "Bernard Black", "/^B.*/" )} {debug_dump( $matches )}

Outputs:

Array ( [0] => Bernard Black )

string preg_replace ( string $subject, string $pattern, string $replace [, int $limit] )

Replaces the matching regular expression $pattern in the source $subject with the value $replace. The amount of replacements is limited to the optional given $limit. The replaced string is returned:

{preg_replace( "Bernard Black", "/^B.*\s/", "Manny " )}

Outputs:

Manny Black

Because the pattern matches 'Bernard ', and replaces it with 'Manny '.

string preg_quote ( $str, [, string $delim] )

Returns the quoted string of the $str. Every character that is a part of the regular expression syntax will be prepended with an addition slash. If the $delim string is given then those characters will also be escaped in the $str:

{preg_quote( "^Bernard/Black" )} {preg_quote( "^Bernard/Black", "/" )}

Outputs:

\^Bernard/Black \^Bernard\/Black

array preg_split ( string $subject, string $pattern )

Returns an array that contains the substrings of the split elements. The elements are split by the regular expression $pattern in the source $subject:

{var $a = preg_split( "These|are|my|elements", "/\|/" )} {debug_dump( $a )}

Outputs:

Array ( [0] => These [1] => are [2] => my [3] => elements )

array preg_grep ( array $subject, string $pattern )

Returns the array alements from the subject that matches the $pattern:

{var $a = preg_grep( array( "Manny", "Bernard", "Fram" ), "/^B/" )} {debug_dump( $a )}

Outputs:

Array ( [1] => Bernard )

String manipulation

string str_replace ( string $before, int $index, int $length, string $replace )

Replaces the part between $index and $index + $length from the string $before with $replace:

{str_replace( "Hello world!", 6, 5, "earth" )}

Outputs:

Hello earth!

See also: str_find_replace ().

string str_find_replace ( string $source, string $find, string $replace [, int $count] )

Searches for the string find in the string source. The first occurence will be replaced with the string replace. If the last parameter count is given, the amount of replacements is limited to this number:

{str_find_replace( "Hello world!", "world", "earth" )}

Outputs:

Hello earth!

See also: str_replace ().

string str_remove ( string $before, int $index, int $length )

Removes the part between index and index + length from the string before:

{str_remove( "Hello world!", 6, 5 )}

Outputs:

Hello!

See also: str_chop (), str_chop_front ().

string str_chop ( string $before, int $number )

Removes the number amount of characters from the end of the string:

{str_chop( "Hello world!", 7 )}

Outputs:

Hello

See also: str_chop_front (), str_remove ().

string str_chop_front ( string $before, string $number )

Removes the $number amount of characters from the beginning of the string:

{str_chop_front( "Hello world!", 6 )}

Outputs:

world!

See also: str_chop (), str_remove ().

string str_append ( string $s1, string $s2 )

Appends the string $s2 to the string $s1:

{str_append( "Hello", " world!" )}

Outputs:

Hello world!

Note that this function is the same as using the dot operator.

See also str_prepend (), str_pad_right (), str_pad_left (), str_fill ().

string str_prepend ( string $s1, string $s2 )

Prepends the string $s2 to the string $s1:

{str_prepend( "Hello", " world!" )}

Outputs:

world!Hello

Note that this function is the same as using the dot operator with switched arguments.

See also str_append (), str_pad_left (), str_pad_right (), str_fill ().

string str_pad_left ( string $str, int $length, string $fill )

Pads the string $str to the length $length with the string $fill. The padding will be prepended to the string $str:

{str_pad_left( " You got the BFG", 20, "-" )}

Outputs:

---- You got the BFG

See also str_pad_right (), str_prepend (), str_append (), str_fill ().

string str_pad_right ( string $str, int $length, string $fill )

Pads the string $str to the length $length with the string $fill. The padding will be appended to the string $str:

{str_pad_right( "You got the BFG ", 20, "-" )}

Outputs:

You got the BFG ----

See also str_pad_left (), str_append (), str_prepend (), str_fill ().

string str_fill ( string $str, int $repeat )

Repeats the string $str for $repeat times and returns it:

{str_fill( "-", 5 )}

Outputs:

-----

See also str_pad_left (), str_pad_right (), str_prepend (), str_append ().

int str_compare ( string $s1, string $s2 )

Compares string $s1 with $s2 and returns 0 if both strings are equal. This function returns a negative value if $s1 is smaller than $s2 and returns a positive value if $s1 is greater than $s2:

{str_compare( "Bernard", "Bernard") // = 0 } {str_compare( "Bernard", "Fran" ) // > 0 } {str_compare( "Fran", "Bernard" ) // < 0 }

See also str_nat_compare ().

int str_nat_compare ( string $sl, string $s2 )

Compares string $s1 with $s2 with a 'natural order' algorithm. This function returns 0 if both strings are equal. A negative value is returned if $s1 is smaller than $s2 and a positive value is returned if $s1 is greater than $s2.

The difference between str_nat_compare_() and str_compare () is how numbers are compared:

{str_compare( "img1.png", "img10.png" ) // > 0 } {str_nat_compare( "img1.png", "img10.png" ) // < 0 }

The first function sorts pure alphabetically. The second functions recognizes the number and therefore says that 'img10' comes after (has a higher number) than 'img1'.

See also str_compare ().

int str_len ( string $str )

Returns the string length, the amount of characters of the string $str:

{str_len( "Bernard" )}

Outputs:

7

This method is the same as str_char_count (). See also str_word_count (), str_paragraph_count ().

int str_char_count ( string $str )

Returns the number of characters in the given string $str:

{str_char_count( "Hello" )}

Outputs:

5

This method is the same as str_len (). See also str_word_count (), str_paragraph_count ().

int str_word_count ( string $str [, $word_sep ] )

Returns the number of words in the given string $str. If no word separator $word_sep is given, the default word seperator is a whitespace:

{str_word_count( "Just a random sentence" )}

Outputs:

4

See also str_char_count (), str_paragraph_count ().

int str_paragraph_count ( string $str )

Returns the number of paragraphs in the given string $str. Each paragraph is supposed to be split a blank line:

{str_paragraph_count( "The first paragraph The second paragraph" )}

Outputs:

2

See also str_char_count (), str_word_count ().

bool str_is_empty ( string $str )

Returns true if the given string $str is empty, otherwise it returns false:

{str_is_empty( "" ) // true }

bool str_contains ( string $source, string $find )

Returns true if the substring $find is found in the source string $source, otherwise this function returns false:

{str_contains( "Don't you dare use the word 'party' as a verb in this shop!", "party" )}

Returns true.

See also str_starts_with (), str_ends_with (), str_index_of (), str_last_index ().

bool str_starts_with ( string $s1, string $s2 )

Returns true if the string $s1 starts with $s2:

{str_starts_with( "Bernard Black" , "Bernard" )}

Returns true.

See also str_ends_with (), str_contains (), str_index_of (), str_last_index ().

bool str_ends_with ( string $s1, string $s2 )

Returns true if the string $s1 ends with $s2:

{str_ends_with( "Bernard Black" , "Black" )}

Returns true.

See also str_starts_with (), str_contains (), str_index_of (), str_last_index ().

int str_index_of ( string $source, string $search [, int $offset ] )

Searches the string $search in $source and returns the begin position of the first occurrence. If an $offset is given, the searching starts at this position. This function returns false if the $search string couldn't be found in the $source:

{str_index_of( "Don't you dare use the word 'party' as a verb in this shop!", "party" )} {str_index_of( "Don't you dare use the word 'party' as a verb in this shop!", "a" )} {str_index_of( "Don't you dare use the word 'party' as a verb in this shop!", "a", 12 )}

Outputs:

29 11 30

See also str_last_index (), str_contains (), str_starts_with (), str_ends_with ().

string str_last_index ( string $s1, string $s2 [, int $offset] )

Does a reverse search the string $search in $source and returns the begin position of the first occurrence. If an $offset is given, the searching starts at this position. This function returns false if the $search string couldn't be found in the $source:

{str_last_index( "Don't you dare use the word 'party' as a verb in this shop!", "party" )} {str_last_index( "Don't you dare use the word 'party' as a verb in this shop!", "a" )} {str_last_index( "Don't you dare use the word 'party' as a verb in this shop!", "a", -25 )}

Outputs:

29 39 30

See also str_index_of (), str_contains (), str_starts_with (), str_ends_with ().

string str_left ( string $str, int $length )

Returns the 'left' $length characters of the string $str:

{str_left( "Bernard Black" , 7 )}

Outputs:

Bernard

See also str_right (), str_mid (), str_at ().

string str_right ( string $str, int $length )

Returns the 'right' $length characters of the string $str:

{str_right( "Bernard Black" , 5 )}

Outputs:

Black

See also str_left (), str_mid (), str_at ().

string str_mid ( string $str, int $index, int $length )

Returns the sub-string between $index and $index + $length from the string $str:

{str_mid( "Bernard Ludwig Black", 8, 6 )}

Outputs:

Ludwig

See also str_left (), str_right (), str_at ().

string str_at ( string $str, int $pos )

Returns the character that is at position $pos in the string $str:

{str_at( "Bernard", 2 )}

Outputs:

r

See also str_left (), str_mid (), str_right ().

string str_chr ( int $char )

Returns one character string with the ASCII value $char:

{str_ord( 65 )}

Outputs:

A

string str_ord ( string $char )

Returns the ASCII value from the character $char:

{str_ord( 'A' )}

Outputs:

65

string str_number ( float $number, int $decimals, string $decimal_sep, string $thousands_sep )

Formats the number $number with the given amount of decimals $decimals, separated with the $decimal_sep character. Thousands are separated with the $thousands_sep character:

{str_number( 30000.141234", 2, ".", "," )}

Outputs:

3,000.14

string str_trim ( string $str, string $charlist = false )

Removes whitespace characters or other characters from the beginning and end of the string. If no $charlist is given, the following characters will be removed:

If a $charlist is given, then the characters in that string will be stripped instead:

{ str_trim( " ...Whoohooo.. " )} { str_trim( " ...Whoohooo.. ", "." )} { str_trim( " ...Whoohooo.. ", " ." )}

Outputs:

...Whoohooo.. ...Whoohooo.. Whoohooo

See also str_trim_left (), str_trim_right (), str_simplify ().

string str_trim_left ( string $str, string $charlist = false )

Removes whitespace characters or other characters from the beginning of the string. This function works the same as str_trim (), except that the characters on the right side are not trimmed:

{ str_trim_left( " ...Whoohooo.. " )} { str_trim_left( " ...Whoohooo.. ", "." )} { str_trim_left( " ...Whoohooo.. ", " ." )}

Outputs:

...Whoohooo.. ...Whoohooo.. Whoohooo..

See also str_trim (), str_trim_right (), str_simplify ().

string str_trim_right ( string $str, string $charlist = false )

Removes whitespace characters or other characters from the end of the string. This function works the same as str_trim (), except that the characters on the left side are not trimmed:

{ str_trim_right( " ...Whoohooo.. " )} { str_trim_right( " ...Whoohooo.. ", "." )} { str_trim_right( " ...Whoohooo.. ", " ." )}

Outputs:

...Whoohooo ...Whoohooo.. ...Whoohooo

See also str_trim (), str_trim_left (), str_simplify ().

string str_simplify ( string $str )

Substitutes newlines, tabs, and multiple spaces from the string $str and replaces it with a single blank. Whitespace in the beginning and at the end of the $str are removed:

{str_simplify( " my\t \n string \n " )}

Outputs:

my string

See also str_trim (), str_trim_left (), str_trim_right ().

array str_split ( string $str, string $separator [, int $max] )

Splits the string $str with the $separator and returns it as an array. If a maximum max is given, the return array will consist of maximum $max elements:

{str_split( "Bernard-Ludwig-Black", "-" )}

Will return an array with the elements:

[0] => "Bernard", [1] => "Ludwig", [2] => "Black".

See also str_join ().

string str_join ( array $array, string $separator )

Joins an array with strings, $array together. Between each element a separator is inserted:

{str_join( array( "Bernard", "Ludwig", "Black" ) , "-"}

Outputs:

Bernard-Ludwig-Black

See also str_split ().

string str_upper ( string $str )

Returns a string with only upper case characters of the source string $str:

{ str_upper( "hEllO worLD" )}

Outputs:

HELLO WORLD

See also str_lower (), str_capitalize ().

string str_lower ( string $str )

Returns a string with only lower case characters of the source string $str:

{ str_lower( "hEllO worLD" )}

Outputs:

hello world

See also str_upper (), str_capitalize ().

string str_capitalize ( string $str )

Returns a string of which the first character is capitalized. Other characters remain unchanged:

{str_capitalize( "hello WORLD" )}

Outputs:

Hello WORLD

See also str_lower (), str_upper ().

string str_reverse ( string $str )

Returns the reversed string of $str:

{str_reverse( "Hello world" )}

Outputs:

dlrow olleH

string str_wrap ( string $str, int $width, string $break [, bool $cut_word] )

Returns a wrapped string of the source string $str. The $width specifies after how the $break character should be inserted. If $cut_word is given and set to true, it will directly insert the $break in the word. Otherwise the word will be finished and the $break will be inserted after the word:

{str_wrap("Don't you dare use the word 'party' as a verb in this shop!", 20, "<br/>\n" )} {str_wrap("Don't you dare use the word 'party' as a verb in this shop!", 20, "\n", true )}

Outputs:

Don't you dare use the <br/> word 'party' as a verb <br/> in this shop! Don't you dare use t he word 'party' as a verb in this shop!

string str_base64_encode ( string $str )

Returns a MIME base64 encoded string from the $str:

{str_base64_encode( "I don't want to be encoded!" )}

Outputs:

SSBkb24ndCB3YW50IHRvIGJlIGVuY29kZWQh

See also str_base64_decode ().

string str_base64_decode ( string $str )

Decodes the given MIME base64 $str and returns the original data:

{str_base64_decode( "SSBkb24ndCB3YW50IHRvIGJlIGVuY29kZWQh" )}

Outputs:

I don't want to be encoded!

See also str_base64_encode ().

Type

bool is_empty ( mixed $val )

Returns true if the given $val is empty, otherwise false. The following examples would return true:

{is_empty( "" )} {is_empty( 0 )} {is_empty( "0" )} {is_empty( false )}

And the rest returns false:

{is_empty( "false" )} {is_empty( "I am empty" )}

Trying to out smart the template engine by saying that string is empty ("I am empty"), does not work :-).

bool is_array ( mixed $val )

Returns true if the given $val is an array, otherwise false:

{is_array( array( 1 ) )}

Returns obviously true.

bool is_float ( mixed $val )

Returns true if the given $val is a float, otherwise false:

{is_float( 2.1 )}

Returns true.

bool is_int ( mixed $val )

Returns true if the given $val is an integer, otherwise false:

{is_int( 2 )}

Returns true.

bool is_bool ( mixed $val )

Returns true if the given $val is a boolean, otherwise false:

{is_bool( false )}

Returns true.

bool is_numberic ( mixed $val )

Returns true if the given $val is an numberic value, otherwise false:

{is_int( 2 )} {is_numberic( 2.2 )}

Return all true.

bool is_object ( mixed $val )

Returns true if the given $val is an object, otherwise false:

{use $myObject} {is_object( $myObject )}

bool is_class ( mixed $val, string $class )

Returns true if the given $val is the class $class, otherwise false:

{use $myObject} {is_class( $myObject, "MyClass" )}

bool is_instance ( mixed $val, string $class )

Returns true if the given $val is an instance of class $class, otherwise false:

{use $myObject} {is_instance( $myObject, "MyClass" )}

bool is_scalar ( mixed $val )

Returns true if the given $val is a scalar; thus containing an integer, float, string, or object. Non scalars, array and object return false:

{is_scalar( "Hello" )}

Return true.

bool is_string ( mixed $val )

Returns true if the given $val is a string, otherwise false:

{is_string( "Hello" )}

Return true.

bool is_set ( mixed $val )

Returns true if the given $val is set, otherwise false:

{var $a} {is_set( $a )}

Return false, but:

{var $a = 5} {is_set( $a )}

Return true.

string get_class ( mixed $val )

Returns the class name of the given object:

{use $obj} {get_class( $obj ) }

Outputs the class name.

string cast_string ( mixed $val )

Casts the input value to a string:

{cast_string(123)}

Returns "123".

int cast_int ( mixed $val )

Casts the input value to a integer:

{cast_int("456")}

Returns 456.

float cast_float ( mixed $val )

Casts the input value to a float:

{cast_float("7.8")}

Returns 7.8.

Web

string url_encode ( string $url )

Returns an encoded string of which the URL specfic characters are written that they can be inserted in an URL:

{url_encode( "myName=Bernard Black" )}

Outputs:

MyName%3DBernard+Black

The URL encode function is handy to create hyperlinks:

<a href="www.ez.no/{url_encode( "myName=Bernard Black" )}">MyLink</a>

See also: url_decode ().

string url_decode ( string $str )

Decodes and returns an url encoded string:

{url_decode( "MyName%3DBernard+Black" )}

Outputs:

myName=Bernard Black

See also: url_encode ().

array url_parse ( string $url )

Parses an URL and returns an array that contains the various components of the given URL $url:

{var $a = url_parse( "http://username:password@hostname/path?arg=value#anchor" )} {debug_dump( $a )}

Outputs:

Array ( [scheme] => http [host] => hostname [user] => username [pass] => password [path] => /path [query] => arg=value [fragment] => anchor )

See also url_build ().

string url_parameters_build ( array $params, string $prefix )

Builds an URL query string from the given $params and returns it as a string:

{url_parameters_build( array( "key" => "val", "firstname" => "Bernard", "lastname" => "Black" ) )}

Outputs:

key=val&firstname=Bernard&lastname=Black

string url_build ( array $data )

Returns an URL build from the given URL components. The given array $data should have the same structure as the url_parse () function:

{var $a = array( "scheme" => "http", "host" => "hostname", "user" => "username", "pass" => "password", "path" => "/path", "query" => "arg=value", "fragment" => "anchor" )} {url_build( $a )}

Outputs:

http://username:password@hostname/path?arg=value#anchor

See also url_parse ().