#49354 [Opn->Asn]: mb_strcut() cutting wrong length when offset is within a multibyte character

From: Date: Fri, 11 Sep 2009 07:28:27 +0000
Subject: #49354 [Opn->Asn]: mb_strcut() cutting wrong length when offset is within a multibyte character
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-142242@lists.php.net to get a copy of this message
ID: 49354 Updated by: moriyoshi@php.net Reported By: mk at zigamorph dot se -Status: Open +Status: Assigned Bug Type: mbstring related Operating System: Linux PHP Version: 5.2.10 -Assigned To: +Assigned To: moriyoshi Previous Comments: ------------------------------------------------------------------------ [2009-08-25 07:33:02] mk at zigamorph dot se Description: ------------ When you use mb_strcut with an offset and this offset happens to fall within a multibyte (utf-8) character mb_strcut moves the start point of the string as to not break a multibyte character. As an undesirable side effect it strips one or more bytes from the end of the cut string. Reproduce code: --------------- $crap = 'AåBäCöDü' /* in utf-8 */ echo mb_strcut($crap, 0, 100, 'UTF-8')."\n"; /* 'AåBäCöDü' as 100 is more than strlen */ echo mb_strcut($crap, 1, 100, 'UTF-8')."\n"; /* 'åBäCöDü' as 100 is more than strlen and we're offset 1 byte */ echo mb_strcut($crap, 2, 100, 'UTF-8')."\n"; /* 'åBäCöD' */ Expected result: ---------------- $crap = 'AåBäCöDü' /* in utf-8 */ echo mb_strcut($crap, 0, 100, 'UTF-8')."\n"; /* 'AåBäCöDü' as 100 is more than strlen */ echo mb_strcut($crap, 1, 100, 'UTF-8')."\n"; /* 'åBäCöDü' as 100 is more than strlen and we're offset 1 byte */ echo mb_strcut($crap, 2, 100, 'UTF-8')."\n"; /* either 'åBäCöDü' or 'BäCöDü' */ ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=49354&edit=1

« previous php.bugs (#142242) next »