note 125429 added to function.mb-str-split
| From: | info at ensostudio dot ru | Date: | Sun, 11 Oct 2020 11:04:02 +0000 |
| Subject: | note 125429 added to function.mb-str-split | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-215566@lists.php.net to get a copy of this message | ||
Note: function return NULL if can't convert argument type.
Polyfill PHP < 7.4 based on package "symfony/polyfill-mbstring":
<?php
function mb_str_split($string, $split_length = 1, $encoding = null)
{
if (null !== $string && !\is_scalar($string) && !(\is_object($string) &&
\method_exists($string, '__toString'))) {
trigger_error('mb_str_split(): expects parameter 1 to be string,
'.\gettype($string).' given', E_USER_WARNING);
return null;
}
if (null !== $split_length && !\is_bool($split_length) &&
!\is_numeric($split_length)) {
trigger_error('mb_str_split(): expects parameter 2 to be int,
'.\gettype($split_length).' given', E_USER_WARNING);
return null;
}
$split_length = (int) $split_length;
if (1 > $split_length) {
trigger_error('mb_str_split(): The length of each segment must be greater than
zero', E_USER_WARNING);
return false;
}
if (null === $encoding) {
$encoding = mb_internal_encoding();
} else {
$encoding = (string) $encoding;
}
if (! in_array($encoding, mb_list_encodings(), true)) {
static $aliases;
if ($aliases === null) {
$aliases = [];
foreach (mb_list_encodings() as $encoding) {
$encoding_aliases = mb_encoding_aliases($encoding);
if ($encoding_aliases) {
foreach ($encoding_aliases as $alias) {
$aliases[] = $alias;
}
}
}
}
if (! in_array($encoding, $aliases, true)) {
trigger_error('mb_str_split(): Unknown encoding
"'.$encoding.'"', E_USER_WARNING);
return null;
}
}
$result = [];
$length = mb_strlen($string, $encoding);
for ($i = 0; $i < $length; $i += $split_length) {
$result[] = mb_substr($string, $i, $split_length, $encoding);
}
return $result;
}
?>
----
Server IP: 45.112.84.4
Probable Submitter: 185.85.3.172 (proxied: 31.129.215.166)
----
Manual Page -- http://php.net/manual/en/function.mb-str-split.php
Edit -- https://master.php.net/note/edit/125429
Del: integrated -- https://master.php.net/note/delete/125429/integrated
Del: useless -- https://master.php.net/note/delete/125429/useless
Del: bad code -- https://master.php.net/note/delete/125429/bad+code
Del: spam -- https://master.php.net/note/delete/125429/spam
Del: non-english -- https://master.php.net/note/delete/125429/non-english
Del: in docs -- https://master.php.net/note/delete/125429/in+docs
Del: other reasons-- https://master.php.net/note/delete/125429
Reject -- https://master.php.net/note/reject/125429
Search -- https://master.php.net/manage/user-notes.php