Meta information

Meta information methods

length

Returns the length of the string.

signature

public function length(): int;

usage

echo $str->length(); //> 10

isEmpty

Checks if the current string is empty.

signature

public function isEmpty(): bool;

usage

if($str->isEmpty()){
    //...
}

isLowerCase

Checks if the current string is in lower case.

signature

public function isLowerCase(): bool;

usage

if($str->isLowerCase()){
    //...
}

isUpperCase

Checks if the current string is in upper case.

signature

public function isUpperCase(): bool;

usage

if($str->isUpperCase()){
    //...
}

isAscii

Checks if the current string contains only ASCII characters.

signature

public function isAscii(): bool;

usage

if($str->isAscii()){
    //...
}

chars

Returns an array of chars.

signature

/**
 * @return string[]
 */
public function chars(): array;

charAt

Returns the char at the specified position. Position can be negative. If position is invalid, an empty string is returned.

signature

public function charAt(int $position): string;

usage

$char = $str->charAt(3);
$char = $str->charAt(-1); // same as $str->charAt($str->length() - 1)

You can also access chars using the str[index] syntax.

$char = $str[3]; // same as $str->charAt(3)
$char = $str[-1]; // same as str->charAt(-1)

codePoints

Returns an array of code points.

signature

/**
 * @return int[]
 */
public function codePoints(): array;

codePointAt

Returns the code point at the specified position. Position can be negative. If position is invalid, -1 is returned.

signature

public function codePointAt(int $position): int;

usage

$cp = $str->codePointAt(3);
$cp = $str->codePointAt(-1); // same as $str->codePointAt($str->length() - 1)

You can also access code points using the str(index) syntax.

$cp = $str(3); // same as $str->codePointAt(3)
$cp = $str(-1); // same as str->codePointAt(-1)