【问题标题】:strtoupper doesn't work with iconv/utf8_decode and FPDFstrtoupper 不适用于 iconv/utf8_decode 和 FPDF
【发布时间】:2020-01-05 08:31:03
【问题描述】:

要将特殊字符打印到 FPDF,我可以使用:

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

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

但这些都不适用于strtoupper。示例:

$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)));

给定:

$text = "Conformità";

所有这些都返回:

确认

代替:

符合标准

更新

此处或其他答案中提出的解决方案不起作用:

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

打印

符合要求

【问题讨论】:

  • @Jeto,正如评论中所说,链接答案提供的解决方案不起作用。
  • 好像do work
  • 它可能不起作用,因为您的字符集已损坏 - 它需要在整个应用程序中设置,最好是相同的,而无需在字符集之间切换。如果你可以在任何地方使用它,我推荐 UTF8。阅读stackoverflow.com/questions/279170/utf-8-all-the-way-through
  • @Mark 我投票决定重新开放。
  • @Mark 我已经在本地测试了this,它输出了正确的结果。你可以试试看。

标签: php utf-8 character-encoding fpdf


【解决方案1】:

你需要使用函数的多字节版本,mb_strtoupper()

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

查看 PHP 文档:PHP mb_strtoupper()

【讨论】:

  • 不。 mb_strtoupper($text); 甚至 mb_strtoupper($text, 'UTF-8'); 打印 CONFORMITÀ。当然我的字体包含那个字符。
猜你喜欢
  • 1970-01-01
  • 2022-12-03
  • 2011-03-04
  • 1970-01-01
  • 1970-01-01
  • 2010-12-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多