对 Perl 的 Entities.pm 感到困惑
好吧,我在这里有点困惑。
我正在尝试为以 utf8 编码的 iPhone 应用程序创建提要。
我们的西班牙语内容有许多拉丁字符(精确字符等)。我使用 Entities.pm 库中的decode_entities 函数,但我注意到它转换为的 char 值破坏了我的提要——我的意思是提要无效,即使周围有 CDATA 标签标题字段。经过进一步调查,我发现这个库正在从 html 实体转换为其相应的 unicode 值,但它使用的是 ISO-8859 而不是 utf8。
如何从 html 实体转换为 utf8?
Ok, I'm a bit confused here.
I am trying to create a feed for an iPhone app encoded in utf8.
There are many latin characters (accute, etc) for our Spanish content. I use the decode_entities function from the Entities.pm lib, but I'm noticing that the char values that it converts to are breaking my feed -- what I mean is that the feed is not valid, even though there are CDATA tags around the title field. Upon further investigation, I've discovered that this lib is converting from an html entity to it's corresponding unicode value but it is using the ISO-8859 instead of utf8.
How do I convert from an html-entity to utf8?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
(如果直接打印 $x,您将收到“打印中的宽字符”警告)。
(You'll get "wide characters in print" warning if you print $x outright).
所以事实证明问题不是 Entities.pm 的问题,而是我用来打开文件的格式的问题。我理所当然地认为 Perl 会自动打开 Utf-8 格式的文件。
我将下面的行添加到文件顶部,提要现在被认为是有效的:
use open ':encoding(utf8)';
So it turns out that the problem was not Entities.pm, but rather the format that I was using to open the file. I took it for granted that Perl would automatically open the file in Utf-8.
I added the line below to the top of my file, and the feed is now considered valid:
use open ':encoding(utf8)';