1

To print special characters to FPDF I can use either:

$this->Cell($w2, 15, iconv('UTF-8', 'windows-1252', $text));

or

$this->Cell($w2, 15, utf8_decode($text));

but neither of those work with strtoupper. Example:

$this->Cell($w2, 15, strtoupper(iconv('UTF-8', 'windows-1252', $text)));
$this->Cell($w2, 15, strtoupper(utf8_decode($text)));

$this->Cell($w2, 15, iconv('UTF-8', 'windows-1252', strtoupper($text)));
$this->Cell($w2, 15, utf8_decode(strtoupper($text)));

Given:

$text = "Conformità";

all of these return:

CONFORMITà

instead of:

CONFORMITÀ

UPDATE

The solutions proposed here or in other answers don't work:

mb_strtoupper($text);
mb_strtoupper($text, 'UTF-8'); 

print

CONFORMITÀ

Mark
  • 3,093
  • 4
  • 32
  • 77
  • @Jeto, as said in the comment the solution procided by the linked answer doesn't work. – Mark Jan 05 '20 at 08:45
  • It seems to [do work](https://3v4l.org/ItWCu) though? – Jeto Jan 05 '20 at 08:54
  • 1
    It probably doesn't work, because your charset is broken - it needs to be set throughout the application, preferably to the same without switching between charsets. I recommend UTF8 if you can use that everywhere. Have a read at https://stackoverflow.com/questions/279170/utf-8-all-the-way-through – Qirel Jan 05 '20 at 09:00
  • @Qirel, the official FAQ of FPDF state: "Don't use UTF-8" and propose to use those conversion, as far as I understand: http://www.fpdf.org/en/FAQ.php – Mark Jan 05 '20 at 09:01
  • @Jeto, it works in PHP *only*. But as I wrote in my question, along with the actual code, it doesn't render in FPDF. – Mark Jan 05 '20 at 09:02
  • @Jeto, done. But it was clearly stated in the question. It wasn't a duplicate in my opinion. – Mark Jan 05 '20 at 09:08
  • 1
    @Mark I voted to reopen. – Jeto Jan 05 '20 at 09:09
  • 1
    @Mark I've tested [this](https://3v4l.org/IK23W) locally and it outputs the correct result. You can try it. – Jeto Jan 05 '20 at 09:21
  • @Jeto, yep! This seems to be the correct solution! – Mark Jan 05 '20 at 09:33

1 Answers1

0

You need to use the multi-bytes version of the function, mb_strtoupper()

echo strtoupper($text); //CONFORMITà
echo mb_strtoupper($text); //CONFORMITÀ

See PHP documentation : PHP mb_strtoupper()

Joffrey Schmitz
  • 2,141
  • 3
  • 16
  • 25
  • Nope. `mb_strtoupper($text);` or even `mb_strtoupper($text, 'UTF-8');` print `CONFORMITÀ`. Of course my font contains that character. – Mark Jan 05 '20 at 08:40