str_split() Function Use in PHP 8.4 and PHP 8.5

According to the official PHP documentation, the str_split() function has not been deprecated or had its behavior changed in PHP 8.4 and PHP 8.5. It remains a standard function, with its core behavior unchanged since PHP 8.2: splitting a string into an array.

Information

Current status: The official manual marks it as available in PHP 5, PHP 7, and PHP 8. The PHP 8.4 and PHP 8.5 deprecation lists do not include str_split.
Behavior: Splits a string into chunks according to the specified length (default is 1). Splits by bytes, not characters; for multibyte strings (such as Chinese), use mb_str_split().
Error handling: Since PHP 8.0.0, if the length parameter is less than 1, a ValueError is thrown (previously it was an E_WARNING and returned false).

Example

<?php
$str = "Hello Friend";

$arr1 = str_split($str);
$arr2 = str_split($str, 3);

print_r($arr1);
print_r($arr2);
?>

14 Views