for php string implment some extemtion functions

<?php


// as_bytes
function as_bytes(string $input): array
{
    $bytes = [];
    $length = strlen($input);
    for ($i = 0; $i < $length; $i++) {
        $bytes[] = ord($input[$i]);
    }
    return $bytes;
}

// as_bytes_mut (modified version, as PHP strings are immutable)
function as_bytes_mut(string &$input): array
{
    $bytes = [];
    $length = strlen($input);
    for ($i = 0; $i < $length; $i++) {
        $bytes[] = ord($input[$i]);
    }
    return $bytes;
}

// as_mut_ptr (not applicable in PHP)

// as_ptr (not applicable in PHP)

// bytes (modified version, as PHP strings are already byte-oriented)
function bytes(string $input): array
{
    $bytes = [];
    $length = strlen($input);
    for ($i = 0; $i < $length; $i++) {
        $bytes[] = $input[$i];
    }
    return $bytes;
}

// contains
function contains(string $haystack, string $needle): bool
{
    return strpos($haystack, $needle) !== false;
}

// ends_with
function ends_with(string $haystack, string $needle): bool
{
    $needleLength = strlen($needle);
    if ($needleLength > 0) {
        return substr($haystack, -$needleLength) === $needle;
    }
    return true; // needle is an empty string
}

// eq_ignore_ascii_case
function eq_ignore_ascii_case(string $a, string $b): bool
{
    return strtolower($a) === strtolower($b);
}

// is_ascii
function is_ascii(string $input): bool
{
    return mb_check_encoding($input, 'ASCII');
}

// len
function len(string $input): int
{
    return strlen($input);
}

// repeat
function repeat(string $input, int $count): string
{
    return str_repeat($input, $count);
}

// replace
function replace(string $input, string $search, string $replace): string
{
    return str_replace($search, $replace, $input);
}

// split
function split(string $input, string $delimiter): array
{
    return explode($delimiter, $input);
}

// starts_with
function starts_with(string $haystack, string $needle): bool
{
    return strpos($haystack, $needle) === 0;
}

// to_lowercase
function to_lowercase(string $input): string
{
    return mb_strtolower($input);
}

// to_uppercase
function to_uppercase(string $input): string
{
    return mb_strtoupper($input);
}

// trim
function trim_all(string $input): string
{
    return trim($input);
}

// trim_start
function trim_start(string $input): string
{
    return ltrim($input);
}

// trim_end
function trim_end(string $input): string
{
    return rtrim($input);
}

?>