php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #73066 mb_at and mb_codepoint_at
Submitted: 2016-09-12 08:40 UTC Modified: 2017-07-23 11:29 UTC
From: masakielastic at gmail dot com Assigned: kalle (profile)
Status: Closed Package: mbstring related
PHP Version: Next Minor Version OS:
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: masakielastic at gmail dot com
New email:
PHP Version: OS:

 

 [2016-09-12 08:40 UTC] 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.


Patches

Add a Patch

Pull Requests

Pull requests:

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-07-23 11:29 UTC] kalle@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: kalle
 [2017-07-23 11:29 UTC] kalle@php.net
Please re-open if you are picking back up the PR, thanks!
 
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Fri Jan 27 03:03:58 2023 UTC