php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #43995 mb_ereg returns byte length of string instead of character length
Submitted: 2008-01-31 15:20 UTC Modified: 2008-02-16 11:54 UTC
From: josmessa at uk dot ibm dot com Assigned: hirokawa (profile)
Status: Not a bug Package: mbstring related
PHP Version: 5.2CVS-2008-01-31 (snap) OS: Windows XP SP2
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: josmessa at uk dot ibm dot com
New email:
PHP Version: OS:

 

 [2008-01-31 15:20 UTC] josmessa at uk dot ibm dot com
Description:
------------
When the $regs argument is provided, mb_ereg will return the length of the matched string. The integer returned though is the byte length of the  string instead of the character length, which seems illogical for a multibyte string function.

Reproduce code:
---------------
<?php
mb_regex_encoding('utf-8');
$string_mb = base64_decode('5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzTvvJXvvJbvvJfvvJjvvJnjgII=');

$regex = '^.*?[[:blank:]]?[[:punct:][:digit:]]+\.?$';

echo "\nMultibyte String without \$regs arg:\t";
var_dump(mb_ereg($regex, $string_mb));
echo "Multubyte String with \$regs arg:\t";
var_dump(mb_ereg($regex, $string_mb, $regs_mb));
echo "Character length of matched string:\t";
var_dump(mb_strlen($regs_mb[0], 'utf-8'));
?>

Expected result:
----------------
Multibyte String without $regs arg:	int(1)
Multubyte String with $regs arg:	int(21)
Character length of matched string:	int(21)

Actual result:
--------------
Multibyte String without $regs arg:	int(1)
Multubyte String with $regs arg:	int(53)
Character length of matched string:	int(21)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-01-31 17:05 UTC] nicholsr@php.net
assign to extension maintainer
 [2008-02-16 11:54 UTC] hirokawa@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

From PHP manual in http://jp.php.net/manual/en/function.mb-ereg.php,
the function returns the byte length of matched part.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 12:01:31 2024 UTC