Perl:解码“乱码”统一码字符串

发布于 2024-12-07 09:45:57 字数 442 浏览 0 评论 0原文

我正在编写一个从某个软件调用的 CGI 脚本(我无法更改)。软件提交的变量给我带来了问题,因为如果它们包含非ascii字符,它们看起来像这样:

ÿFFFFDEetta er texti meÿFFFFF0 ÿFFFFEDslenskum stÿFFFFF6fum

而不是

Þetta er texti með íslenskum stöfum代码>.

我尝试过修改 Encode::decode 函数,但没有任何结果 - 我所做的只是改变 ÿ 的表示方式。

是的,我有点困惑。我该怎么做才能将所有 ÿFFFFDE 更改为 Þ 等,而不需要单独替换每个非 ascii 字符(这不是解决方案,因为这需要为我什至不会说的语言工作)?

I'm working on a CGI script that is called from a piece of software (that I can't change). The variables submitted by the software are giving me problems, because if they contain non-ascii characters they look like this:

ÿFFFFDEetta er texti meÿFFFFF0 ÿFFFFEDslenskum stÿFFFFF6fum

instead of

Þetta er texti með íslenskum stöfum.

I've tried messing with the Encode::decode function but nothing has come of it - all I've gotten it to do is change how the ÿ gets represented.

So yeah, I'm kind of stumped. What do I do to change all the ÿFFFFDEs into Þs and so on, without resorting to replacing each non-ascii character individually (which is not a solution because this needs to work for languages I don't even speak)?

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

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

发布评论

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

评论(1

极致的悲 2024-12-14 09:45:57
use Encode qw(decode);
use Encode::Escape qw();

$_ = 'ÿFFFFDEetta er texti meÿFFFFF0 ÿFFFFEDslenskum stÿFFFFF6fum';
s/ÿFFFF/\\x/g;
decode('iso-8859-1', decode('unicode-escape', $_));
# returns 'Þetta er texti með íslenskum stöfum'
use Encode qw(decode);
use Encode::Escape qw();

$_ = 'ÿFFFFDEetta er texti meÿFFFFF0 ÿFFFFEDslenskum stÿFFFFF6fum';
s/ÿFFFF/\\x/g;
decode('iso-8859-1', decode('unicode-escape', $_));
# returns 'Þetta er texti með íslenskum stöfum'
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文