Req #73066 [Opn->Csd]: mb_at and mb_codepoint_at
Edit report at https://bugs.php.net/bug.php?id=73066&edit=1
ID: 73066
Updated by: kalle@php.net
Reported by: masakielastic at gmail dot com
Summary: mb_at and mb_codepoint_at
-Status: Open
+Status: Closed
Type: Feature/Change Request
Package: mbstring related
PHP Version: Next Minor Version
-Assigned To:
+Assigned To: kalle
Block user comment: N
Private report: N
New Comment:
Please re-open if you are picking back up the PR, thanks!
Previous Comments:
------------------------------------------------------------------------
[2016-09-12 08:40:27] masakielastic at gmail dot com
Description:
------------
I propose mb_at and mb_codepoint_at.
string mb_at ( string $string , int $offset [, string $encoding = mb_internal_encoding() ] )
int mb_codepoint_at ( string $string , int $offset [, string $encoding = mb_internal_encoding() ] )
The one of usage of these functions is to iterate over all the chars in string.
$str = "Cat!\u{1f431}";
$gen = (function($str) {
for ($i = 0, $len = mb_strlen($str); $i < $len; ++$i) {
yield mb_at($str, $i);
}
})($str);
foreach ($gen as $char) {
echo $char, PHP_EOL;
}
mb_codepoint_at is equivalent to the following code:
mb_ord(mb_substr($str, $i, 1));
str_at and str_codepoint_at are worthy of consideration.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=73066&edit=1
Thread (2 messages)