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
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
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-2022 The PHP Group
All rights reserved.
Last updated: Fri Dec 09 09:05:53 2022 UTC