php-src icon indicating copy to clipboard operation
php-src copied to clipboard

MB_CASE_TITLE treats entities as words (in contrast to uc_words)

Open grmblfrz opened this issue 1 year ago • 4 comments

Description

The following code:

<?php
$txt = 'acme &amp; co';

echo mb_convert_case($txt, MB_CASE_TITLE, 'UTF-8'), PHP_EOL;

Resulted in this output:

Acme &Amp; Co

But I expected this output instead:

Acme &amp; Co

Using uc_words produces the expected result:

<?php
$txt = 'acme &amp; co';

echo ucwords($txt), PHP_EOL;

results in

Acme &amp; Co

PHP Version

PHP 8.4.5, PHP 8.2.26

Operating System

No response

grmblfrz avatar Apr 03 '25 10:04 grmblfrz

Maybe this seems not include in DerivedCoreProperties.txt.

youkidearitai avatar Apr 03 '25 13:04 youkidearitai

I think this is not a bug. Because mb_convert_case is depends on Unicode. In this case, & is not alphabet. And it is not include at "Case_Ignorable" in DerivedCorePreperties.txt. Therefore, mb_convert_case can't convert to &amp;. That result is &Amp;

By the way, if fix(modify) this issue, this is BC breaks.

Please see also:

  • https://bugs.php.net/bug.php?id=65544
  • https://bugs.php.net/bug.php?id=46607

@alexdowad What do you think?

youkidearitai avatar May 29 '25 08:05 youkidearitai

@grmblfrz, thanks for the report. As @youkidearitai said, mb_convert_case is intended to follow the case conversion algorithms in the Unicode standard.

If it doesn't, please feel free to open a bug report and show us in what way mb_convert_case does not follow the Unicode standard.

Showing us that it doesn't behave the same as ucwords doesn't mean much, because it is not intended to follow the behavior of ucwords.

alexdowad avatar Jun 08 '25 09:06 alexdowad

Closing this one. Feel free to re-open if anyone has further input.

alexdowad avatar Nov 09 '26 00:11 alexdowad