|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #74264 Wrong position with grapheme_strr*pos() functions and negative offsets
Submitted: 2017-03-17 15:42 UTC Modified: -
From: webmaster at apprendre-php dot com Assigned:
Status: Open Package: intl (PECL)
PHP Version: 5.6.30 OS: Mac OS X Yosemite 10.10.5
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 — but make sure to vote on the bug!
Your email address:
Solve the problem:
34 - 28 = ?
Subscribe to this entry?

 [2017-03-17 15:42 UTC] webmaster at apprendre-php dot com

I'm currently working on a group of classes abstracting operations on ASCII and UTF8 strings using either the native string functions or multibytes functions or graphemes cluster functions from intl extension.

It seems the grapheme_strripos() and grapheme_strrpos() functions don't calculate a position right when they receive an accentuated string AND a negative offset. However the position calculus is correct when these functions receive an accentuated string AND a positive offset.

If you look at the attached piece of test script, the statements #5 and #6 are expected to return int(5) but they return int(6) instead. If you try this behavior with mb_strrpos() and mb_strripos() functions instead, the output will be int(5) as expected.

You can find the tested scenario here:

Test script:
// Expecting int(6) [3 times]
var_dump(grapheme_strrpos('dejaaaa', 'a', 2));   // int(6)
var_dump(grapheme_strrpos('déjàààà', 'à', 2));   // int(6)
var_dump(grapheme_strripos('DÉJÀÀÀÀ', 'à', 2));  // int(6)

// Expecting int(5) [3 times]
var_dump(grapheme_strrpos('dejaaaa', 'a', -2));  // int(5)
var_dump(grapheme_strrpos('déjàààà', 'à', -2));  // int(6)
var_dump(grapheme_strripos('DÉJÀÀÀÀ', 'à', -2)); // int(6)

// Expecting int(5) [3 times]
var_dump(mb_strrpos('dejaaaa', 'a', -2));        // int(5)
var_dump(mb_strrpos('déjàààà', 'à', -2));        // int(5)
var_dump(mb_strripos('DÉJÀÀÀÀ', 'à', -2));       // int(5)


Add a Patch

Pull Requests

Add a Pull Request

PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Fri Oct 30 02:01:24 2020 UTC