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
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
45 - 15 = ?
Subscribe to this entry?

 
 [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-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 09:01:28 2024 UTC