note 130246 added to function.grapheme-str-split
| From: | cygx1@blackhole.io | Date: | Sun, 13 Apr 2025 20:06:46 +0000 |
| Subject: | note 130246 added to function.grapheme-str-split | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-222085@lists.php.net to get a copy of this message | ||
Here is a userland implementation that can be included in code that needs to support PHP 8.3 and
below:
<?php
if (!function_exists('grapheme_str_split')) {
function grapheme_str_split(string $string, int $length = 1): array|false
{
if ($length < 1) {
throw new \ValueError('Argument #2 ($length) must be greater than 0 and less than or equal
to 1073741823');
}
try {
return preg_split('/(\X{' . $length . '})/u', $string, -1,
PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
} catch (\Throwable $e) {
return false;
}
}
}
?>
----
Server IP: 45.112.84.4
Probable Submitter: 45.112.84.18 (proxied: 184.64.46.210)
----
Manual Page -- https://php.net/manual/en/function.grapheme-str-split.php
Edit -- https://main.php.net/note/edit/130246
Del: integrated -- https://main.php.net/note/delete/130246/integrated
Del: useless -- https://main.php.net/note/delete/130246/useless
Del: bad code -- https://main.php.net/note/delete/130246/bad+code
Del: spam -- https://main.php.net/note/delete/130246/spam
Del: non-english -- https://main.php.net/note/delete/130246/non-english
Del: in docs -- https://main.php.net/note/delete/130246/in+docs
Del: other reasons-- https://main.php.net/note/delete/130246
Reject -- https://main.php.net/note/reject/130246
Search -- https://main.php.net/manage/user-notes.php