Built-in functions: string

@split <delimiter>, <string>

Splits the string into an array using the specified delimiter.

Alias: @explode

“,” @split “a,b,c” // result: [ a, b, c ]

@length <string>

Returns the length of a string.

@length abc

> 3

@substr <string>, <start>, <length>

Returns a substring from the given string.

$a: @substr “abcde”, 1, 3

@echo $a

> bcd

@str_pos <haystack>, <needle>

Returns the position of the first occurrence of a substring.

@strpos abcbdbe, b // return 1

@str_m_pos <haystack>, <needle>

Returns all matched positions (case-sensitive).

@strpos abcbdbe, b // return [1,3,5]

@str_i_pos <haystack>, <needle>

Returns the first position of a substring (case-insensitive).

@strpos abcbdbe, B // return 1

@str_m_i_pos <haystack>, <needle>

Returns all positions of needle in haystack (case-insensitive).

@strpos abcbdbe, B // return [1,3,5]

@str_to_lower <string>

Converts the string to lowercase.

@str_to_lower Hello World // return “hello world”

@str_to_upper <string>

Converts the string to uppercase.

@str_to_lower Hello World // return “HELLO WORLD”

@is_preg_match $pattern, $subject, $is_unicode

Check if the string `$subject` matches the regular expression `$pattern`.

– pattern: Regular expression pattern (e.g. /abc/, or /[\p{L}]/u for Unicode).

– subject: The string to test.

– is_unicode (default false): If true, treat pattern as Unicode.

Returns true if at least one match is found, otherwise false.

@is_preg_match ”[a-z], “abc”, false

@echo $?

> true

@preg_replace_all <pattern>, <replacement>, <subject>, <is_unicode>

Replace all occurrences matching <pattern> in <subject> with <replacement>.

– pattern: Regular expression pattern (e.g. /[0-9]+/).

– replacement: Replacement string.

– subject: The input string.

– is_unicode (default false): If true, treat pattern as Unicode.

Returns the string after replacements.

@preg_match_all “/[a-z]/”, “abc”, false

@print $@

> arr:

> [

>      0 => a

>      1 => b

>      2 => c

> ]

 

@preg_match_all <pattern>, <subject>, <is_unicode>

Find all substrings in `$subject` that match the regular expression `$pattern`.

– pattern: Regular expression pattern (e.g. /[a-z]/ or /[\p{L}]/u).

– subject: The string to search.

– is_unicode (default false): If true, treat pattern as Unicode.

@preg_replace_all “/[\\p{L}]/u”, “*”, Привет-мир

, false

@echo $?

> ******-***