String functions

Different languages have different syntax for getting substrings and pushing element to array. Gutt provides solid common functions for working with strings, numbers and maps.

All this functions is just a declaration. In real life stringifiers and platforms may return different values. I hope there is nothing critical, but i have to warning you.

str_sub#

str_sub($string, $start[, $length])

Returns substring. Returned value can be preserved to variable and go to output

Parameters

$string

input string

$start

start position. Can be zero or positive number

$length

length of substring. Can be any number. If negative then that many characters will be omitted from the end of string

Examples

{str_sub('input string', 2)} <!-- put string -->{str_sub('input string', 3, 6)} <!-- ut str -->{str_sub('input string', 1, -2)} <!-- nput stri -->

str_len#

str_len($string)

Returns string's length

Parameters

$string

input string

Examples

{str_len('input string')} <!-- 12 -->

str_replace#

str_replace($string, $replace, $subject)

Returns new string with replaced substrings

Parameters

$string

input string

$replace

string which search to replace

$subject

string which replaced on

Examples

{str_replace('input string', 't', 'f')} <!-- inpuf sfring -->

str_pad#

str_pad($string, $length, $substring)

Returns padded $string on the right side until $length with $substring

Parameters

$string

input string

$length

finally string length

$substring

padding string

Examples

{str_pad('string', 10, '~')} <!-- string~~~~ -->

str_pad_right#

Alias for str_pad

str_pad_left#

str_pad_left($string, $length, $substring)

Returns padded $string on the left side until $length with $substring

Parameters

$string

input string

$length

finally string length

$substring

padding string

Examples

{str_pad_left('string', 10, '~')} <!-- ~~~~string -->

str_pad_both#

str_pad_both($string, $length, $substring)

Returns padded $string on both sides until $length with $substring

Parameters

$string

input string

$length

finally string length

$substring

padding string

Examples

{str_pad_both('string', 10, '~')} <!-- ~~string~~ -->

str_split#

str_split($string, $splitter)

Returns map of chunks of splitting $string by $splitter

Parameters

$string

input string

$splitter

splitter string. Can be empty

Examples

<var name={$chunks} value={str_split('string', '')} /><for-each item={$chunk} from={$chunks}>	{$chunk}.</for-each><!-- s.t.r.i.n.g. -->

str_pos#

str_pos($string, $substring)

Returns the position of the first occurrence of a substring in a string. If there is no occurrence of substring in string then function returns -1

Parameters

$string

input string

$substring

searching string

Examples

{str_pos('string', 'i')} <!-- 3 -->

str_lower#

str_lower($string)

Returns lowercassed string

Parameters

$string

input string

Examples

{str_lower('StrING')} <!-- string -->

str_upper#

str_upper($string)

Returns uppercassed string

Parameters

$string

input string

Examples

{str_upper('StrING')} <!-- STRING -->

str_upfirst#

str_upfirst($string)

Returns string with uppercassed first letter of each word

Parameters

$string

input string

Examples

{str_upfirst('string with spaces')} <!-- String With Spaces -->

str_camel#

str_camel($string)

Returns string with removed spaces between words and uppercassed first letter from second word

Parameters

$string

input string

Examples

{str_camel('string with spaces')} <!-- stringWithSpaces -->

str_kebab#

str_kebab($string)

Returns string with replaced spaces for dashes between words

Parameters

$string

input string

Examples

{str_kebab('string with spaces')} <!-- string-with-spaces -->

str_trim#

str_trim($string)

Returns string with removed spaces from both sides

Parameters

$string

input string

Examples

{str_trim(' string with spaces ')}

str_ltrim#

str_ltrim($string)

Returns string with removed spaces from the left side

Parameters

$string

input string

Examples

{str_ltrim(' string with spaces ')}

str_rtrim#

str_rtrim($string)

Returns string with removed spaces from the right side

Parameters

$string

input string

Examples

{str_rtrim(' string with spaces ')}

str_htmlescape#

str_htmlescape($string)

Converts special characters to HTML entities

Parameters

$string

input string

Examples

{str_htmlescape('<img src="./logo.svg" alt="Logo" />')}<!-- &lt;img src=&quot;./logo.svg&quot; alt=&quot;Logo&quot; /&gt; -->

str_urlencode#

str_urlencode($string)

Returns URL-encodes string

Parameters

$string

input string

Examples

{str_urlencode('http://localhost:8080/index.html?param=value&amp;param2=value2')}<!-- http%3A%2F%2Flocalhost%3A8080%2Findex.html%3Fparam%3Dvalue%26param2%3Dvalue2 -->

str_urldecode#

str_urldecode($string)

Returns decoded URL-encoded string

Parameters

$string

input string

Examples

{str_urldecode('http%3A%2F%2Flocalhost%3A8080%2Findex.html%3Fparam%3Dvalue%26param2%3Dvalue2')}<!-- http://localhost:8080/index.html?param=value&amp;param2=value2 -->