#43995 [Asn->Bgs]: mb_ereg returns byte length of string instead of character length
| From: | hirokawa@php.net | Date: | Sat, 16 Feb 2008 11:54:08 +0000 |
| Subject: | #43995 [Asn->Bgs]: mb_ereg returns byte length of string instead of character length | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-122342@lists.php.net to get a copy of this message | ||
ID: 43995
Updated by: hirokawa@php.net
Reported By: josmessa at uk dot ibm dot com
-Status: Assigned
+Status: Bogus
Bug Type: mbstring related
Operating System: Windows XP SP2
PHP Version: 5.2CVS-2008-01-31 (snap)
Assigned To: hirokawa
New Comment:
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.
Previous Comments:
------------------------------------------------------------------------
[2008-01-31 17:05:20] nicholsr@php.net
assign to extension maintainer
------------------------------------------------------------------------
[2008-01-31 15:20:09] 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)
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=43995&edit=1