PHP utf-8 问题
我正在使用 pdf 生成器类(TCPDF)从一些 html 生成 pdf 文件。问题是 html 文本有一些 utf8 和 unicode 字符。这个类支持这些角色。
我已经完成设置,并且在本地主机上一切正常。但是当我将文件上传到我的网络主机时,我得到一个白页。我使用完全相同的代码。
如果我删除 unicode 和 utf-8 字符,它就可以工作。我已经复制了脚本,但在服务器上它不起作用。是否有一个 php 设置来处理这些字符?也许 php.ini 中有什么东西?谢谢
I'm using a pdf generator class(TCPDF) to generate a pdf file from some html. The problem is that that html text has some utf8 and unicode characters. This class has support for those characters.
I've made the settings and all works just fine on localhost. But when I upload the files to my web host, I get a white page. I use exacty the same code.
If I delete the unicode and utf-8 characters it works. I've copied the script but on the server it is not working. It is there a php setting for handling those characters? Something in php.ini maybe? Thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
除了确保 PHP 安装了 mbstring 扩展之外,还要确保您在脚本中使用
mb_internal_encoding('UTF-8');
或在 php.ini 中设置 PHP 的编码。您还需要确保 TCPDF 中指定的字体支持 UTF-8 字符。多年来我在这方面遇到了很大的问题,最终决定使用与 TCPDF 捆绑在一起的 Freesans 和 Freeserif 字体。
另外,在实例化 TCPDF 类时,请确保已设置类构造函数的第四个和第五个参数。如果省略,它们应该默认为 TRUE,UTF-8,但我总是指定以确保。
检查 TCPDF 构造函数的文档
As well as making sure that PHP has the mbstring extension installed, make sure you're setting PHP's encoding in the script with
mb_internal_encoding('UTF-8');
or in php.ini.You also need to make sure that the font being specified in TCPDF has support for UTF-8 characters. I've had big problems with this over the years and eventually just decided to use the Freesans and Freeserif fonts that are bundled with TCPDF.
Also when instantiating the TCPDF class make sure you have set the 4th and 5th parameters of the class constructor. If omitted they should default to TRUE, UTF-8 but I always specify to make sure.
Check the docs for the TCPDF constructor