fpdf 中导出的符号错误... ñ作为ñ ..?

发布于 2024-10-10 18:07:33 字数 70 浏览 0 评论 0原文

我不知道问题是什么,但每当我从 $_POST 函数调用字母 ñ 时,它就会将其作为 ñ 放入我的 fpdf 中。知道为什么吗?

I dont know whats the problem but whenever I call the letter ñ from $_POST function it puts it in my fpdf as ñ .. any idea why?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

雨落星ぅ辰 2024-10-17 18:07:33

您的字符串编码错误。它是 UTF-8 但我认为你需要 Latin-1 左右..

你可以在你的字符串上使用 utf8_decode() :

echo utf8_decode("ñ"); // prints ñ

Your string has a wrong encoding. It's UTF-8 but I think you need Latin-1 or so..

You can use utf8_decode() on your strings:

echo utf8_decode("ñ"); // prints ñ
一口甜 2024-10-17 18:07:33

我也花了相当多的时间试图让它发挥作用,并认为以下解释可能对其他人有帮助。

如果唯一的问题是 £/€ 或类似字符,则无需编写自己的复杂函数。

这是我使用过的内容(取自此线程和网上的其他线程):-

$pdf->SetY(220); // set the y co-ord before output //
$monthlyRent = utf8_decode("£" . number_format($monthlyRent, 2)); // 2 dec places //
// previously $monthlyRent is pulled from the MySql db as $array['_monthlyRent'];
$pdf->Write(5,'Gross monthly rent: ' . $monthlyRent); // outputs £980 or whatever. //

效果不错,但一定记得在与 utf8_decode(); 相同的行,否则就会搞砸!

希望这对像我一样挣扎了几个小时的可怜的草皮有所帮助!

I too have spent a fair amount of time trying to get this to work and thought the following explanation might be helpful for others.

No need to write your own complex functions if the only problem is a £/€ or similar character.

Here's what I have used (taken from this thread and others on the net):-

$pdf->SetY(220); // set the y co-ord before output //
$monthlyRent = utf8_decode("£" . number_format($monthlyRent, 2)); // 2 dec places //
// previously $monthlyRent is pulled from the MySql db as $array['_monthlyRent'];
$pdf->Write(5,'Gross monthly rent: ' . $monthlyRent); // outputs £980 or whatever. //

Works a treat but do remember to do the number_format($yourval, 2) in the same line as the utf8_decode(); or it screws up!

Hope this is helpful to some poor sod, who like me, has struggled for a few hours!

独享拥抱 2024-10-17 18:07:33

另一种解决方案是使用 Unicode (UTF-8) 支持来扩展 FPDF。有一个补丁: http://acko.net/node/56

The alternative solution would be to extend FPDF with Unicode (UTF-8) support. There is a patch for that: http://acko.net/node/56

桃扇骨 2024-10-17 18:07:33

我们曾经遇到过这个问题,并使用

utf8_decode("foo bar");

解决了问题(当然取决于数据是否来自用户、数据库……)。不要忘记在标头中以 UTF-8 格式将文件传递给用户

header("Content-type: application/pdf; charset=utf-8");

We had the problem once and using

utf8_decode("foo bar");

solved the problem (depends of course if the data is comming from the user, a database,...). Don't forget to deliver the file to the user in UTF-8 as well in the header

header("Content-type: application/pdf; charset=utf-8");
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文