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
$stringinput string
$startstart position. Can be zero or positive number
$lengthlength 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
$stringinput string
Examples
{str_len('input string')} <!-- 12 -->str_replace#
str_replace($string, $replace, $subject)Returns new string with replaced substrings
Parameters
$stringinput string
$replacestring which search to replace
$subjectstring 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
$stringinput string
$lengthfinally string length
$substringpadding 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
$stringinput string
$lengthfinally string length
$substringpadding 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
$stringinput string
$lengthfinally string length
$substringpadding string
Examples
{str_pad_both('string', 10, '~')} <!-- ~~string~~ -->str_split#
str_split($string, $splitter)
Returns map of chunks of splitting $string by $splitter
Parameters
$stringinput string
$splittersplitter 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
$stringinput string
$substringsearching string
Examples
{str_pos('string', 'i')} <!-- 3 -->str_lower#
str_lower($string)Returns lowercassed string
Parameters
$stringinput string
Examples
{str_lower('StrING')} <!-- string -->str_upper#
str_upper($string)Returns uppercassed string
Parameters
$stringinput string
Examples
{str_upper('StrING')} <!-- STRING -->str_upfirst#
str_upfirst($string)Returns string with uppercassed first letter of each word
Parameters
$stringinput 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
$stringinput string
Examples
{str_camel('string with spaces')} <!-- stringWithSpaces -->str_kebab#
str_kebab($string)Returns string with replaced spaces for dashes between words
Parameters
$stringinput string
Examples
{str_kebab('string with spaces')} <!-- string-with-spaces -->str_trim#
str_trim($string)Returns string with removed spaces from both sides
Parameters
$stringinput string
Examples
{str_trim(' string with spaces ')}str_ltrim#
str_ltrim($string)Returns string with removed spaces from the left side
Parameters
$stringinput string
Examples
{str_ltrim(' string with spaces ')}str_rtrim#
str_rtrim($string)Returns string with removed spaces from the right side
Parameters
$stringinput string
Examples
{str_rtrim(' string with spaces ')}str_htmlescape#
str_htmlescape($string)Converts special characters to HTML entities
Parameters
$stringinput string
Examples
{str_htmlescape('<img src="./logo.svg" alt="Logo" />')}<!-- <img src="./logo.svg" alt="Logo" /> -->
str_urlencode#
str_urlencode($string)Returns URL-encodes string
Parameters
$stringinput string
Examples
{str_urlencode('http://localhost:8080/index.html?param=value&param2=value2')}<!-- http%3A%2F%2Flocalhost%3A8080%2Findex.html%3Fparam%3Dvalue%26param2%3Dvalue2 -->
str_urldecode#
str_urldecode($string)Returns decoded URL-encoded string
Parameters
$stringinput string
Examples
{str_urldecode('http%3A%2F%2Flocalhost%3A8080%2Findex.html%3Fparam%3Dvalue%26param2%3Dvalue2')}<!-- http://localhost:8080/index.html?param=value&param2=value2 -->