# [PATCH] Bug #46806 - mb_strimwidth

- Thread: https://externals.io/message/42413
- Original archive: https://news-web.php.net/php.internals/42413
- Started by Henrique M. Decaria on 2008-12-30T16:24:15+00:00
- Messages: 2
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · RFCs at https://externals.io/rfc.md · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #42413 — Henrique M. Decaria — 2008-12-30T16:24:15+00:00

URL: https://externals.io/message/42413#42413

Hello guys,

Looking in the subject mentioned bug report, it seems that the attached
patch might do the trick and make the `mb_strimwidth()` function work as
explained in the php manual (http://br2.php.net/mb_strimwidth).
According to it, the function should trim up to the defined width and append
the trimmarker, that being said, the following code should return "hello..."
not "he..."

echo mb_strimwidth('helloworld', 0, 5, '...', 'UTF-8');

The change in the file is:

-    pc.width = width - mkwidth;
+    pc.width = width;

I am not sure why there is this "- mkwidth" there, but it seems to be used
to remove the last "mkwidth" characters from the trimmed string so it would
be replaced with the trimmarker.

It could be that the test file for this function is incorrect (i can't
guarantee as I am having issues with Japanese characters here). So please,
if you could have a look and see if it works as expected with this patch it
would be great.

Thanks,

Henrique

---

## #42473 — Moriyoshi Koizumi — 2009-01-03T16:42:32+00:00

URL: https://externals.io/message/42413#42473 · In reply to: #42413

Hi,

This behavior seems strange, but the rationale of this function is that 
the (east asian) width of the resulting string does not exceed the 
specified value so that it would fit to a fixed sized box when rendered 
in the browser, assuming the string would be displayed with a monospace 
font.  So, it is the document that is wrong.

Regards,
Moriyoshi

(2008/12/31 1:24), Henrique M. Decaria wrote:
> Hello guys,
>
> Looking in the subject mentioned bug report, it seems that the attached
> patch might do the trick and make the `mb_strimwidth()` function work as
> explained in the php manual (http://br2.php.net/mb_strimwidth).
> According to it, the function should trim up to the defined width and append
> the trimmarker, that being said, the following code should return "hello..."
> not "he..."
>
> echo mb_strimwidth('helloworld', 0, 5, '...', 'UTF-8');
>
> The change in the file is:
>
> -    pc.width = width - mkwidth;
> +    pc.width = width;
>
> I am not sure why there is this "- mkwidth" there, but it seems to be used
> to remove the last "mkwidth" characters from the trimmed string so it would
> be replaced with the trimmarker.
>
> It could be that the test file for this function is incorrect (i can't
> guarantee as I am having issues with Japanese characters here). So please,
> if you could have a look and see if it works as expected with this patch it
> would be great.
>
> Thanks,
>
> Henrique
>
>


-- 
-- moriyoshi
