|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #37391 PREG_OFFSET_CAPTURE not UTF-8 aware when using u modifier
Submitted: 2006-05-09 22:57 UTC Modified: 2006-05-10 07:03 UTC
From: mike at silverorange dot com Assigned:
Status: Not a bug Package: PCRE related
PHP Version: 5.1.4 OS: Linux
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.
Block user comment
Status: Assign to:
Bug Type:
From: mike at silverorange dot com
New email:
PHP Version: OS:


 [2006-05-09 22:57 UTC] mike at silverorange dot com
When using preg_match_all() with the PREG_OFFSET_CAPTURE flag, the returned match offsets are in octets rather than characters.

PCRE is compiled with --enable-utf8 and I am using the u modifier in my regular expression.

Reproduce code:
$matches = array();
$reg_exp = "/B/u";
// UTF8 represents A-euro-BC
$string = "A\xe2\x82\xacBC"; 
preg_match_all($reg_exp, $string, $matches, PREG_OFFSET_CAPTURE);

Expected result:
    [0] => Array
            [0] => Array
                    [0] => B
                    [1] => 2

Actual result:
    [0] => Array
            [0] => Array
                    [0] => B
                    [1] => 4


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2006-05-10 07:03 UTC]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at and the instructions on how to report
a bug at

 [2012-03-19 00:00 UTC] harald dot lapp at gmail dot com
I am not sure, where the manual mentions, that PREG_OFFSET_CAPTURE is not "UTF-8" 
aware. And even if it was, it is still very, very, very annoying, Any chances, 
that this behaviour could get changed?
PHP Copyright © 2001-2018 The PHP Group
All rights reserved.
Last updated: Wed Jul 18 05:01:24 2018 UTC