CKTIS / PHP
str_split()
Split into chunks of a positive number of bytes.
Version: PHP 8.4; repository runtime, production runtime not attested
Syntax
str_split(string $string, int $length = 1): arraySplit into chunks of a positive number of bytes. The final chunk can be shorter. UTF-8 characters can be split into invalid individual bytes, so use a character-aware function for text units. Since PHP 8.2 an empty input produces an empty array; a length below one raises ValueError.
Signature
str_split(string $string, int $length = 1): array
Example output
[["AB","CD","E"],["c3","a9"],[]]
Examples
<?php
echo json_encode([str_split("ABCDE",2),array_map("bin2hex",str_split("\u{00E9}")),str_split("")]);
Result
[["AB","CD","E"],["c3","a9"],[]]