[PHP-NOTES] note 130246 added to function.grapheme-str-split

[email protected] ("[email protected]")
Newsgroups php.notes
Message-ID <[email protected]>
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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.